Nateo Tutorials -> Data Objects

# Nateo Tutorial: Data Objects

All data objects you store in the NtTimeChartControl must be instances of NtDataObject or subclasses of that. So let us take a look how NtDataObject is defined:

public class NtDataObject
{
public ulong objId;
public int dataTypeId;
public DateTime dt;
public DateTime dtEnd;
public object dataItem;
}

In the tutorial before we created data objects by simply instantiating NtDataObjects and setting their dataItem member field. But how do you proceed if your data is not just a text or a number but a more complex data strucutre like a class or struct?
Suppose you want to store 1000 data objects of type MyClass and 2000 data objects consisting of two strings, each. While MyClass is already defined, you do not have a class for your string pair, yet.
For the 1000 MyClass objects, you will create 1000 instances of NtDataObject and assign one MyClass object to the dataItem member of one of the NtDataObjects and then put all NtDataObjects to the NtTimeChartControl by calling the InsertDataObjects() method.
For the string pairs you have two options:

1. Define another class type MyStringPair and proceed exactly as with the MyClass objects.
2. Derive your own subclass of NtDataObject with two additional members of type string. Then simply instantiate objects of this new type, assign the strings and insert these into the NtTimeChartControl. In this case you might even ignore the dataItem member of NtDataObject.

Option 2 might look like this:

public class MyDataObject : NtDataObject
{
public string str1;
public string str2;
}

Setting up the NtDataObjects correctly
When instatiating the NtDataObjects for storage in the Time Chart, you must specify a unique objId for each of them, specify the DateTime members correctly and most of all you must set the dataTypeId properly for each of them: For all MyClass elements, you might set 100, for all of your string pairs (no matter which option you selected) you might set 200.

Implement the NtApplication Interface correctly
To keep it simple, we assume you want to display all your data as texts. To display a MyClass correctly, the MyClass.ToString() method shall be fine. For the string pair you always want to use str2 for display. Then the implementation of the NtApplication is pretty simple:

//Interface NtApplication
public bool NtIsHoliday(DateTime dt) { return false; }
public bool NtIsWeekend(DateTime dt) { return false; }
public string NtGetTooltipText(NtDisplayObject tooltipDisplayObject, int ttType)
{
if (tooltipDisplayObject.DataObject.dataTypeId == 100) return tooltipDisplayObject.DataObject.dataItem.ToString();
else return ((MyDataObject)tooltipDisplayObject.DataObject).str1; //we use str1 for the tootlip
}
public string NtGetText(NtDataObject ntDo)
{
if (ntDo.dataTypeId == 100) return ntDo.dataItem.ToString();
else return ((MyDataObject)ntDo).str2; //we use str2 for display
}
public double NtGetDouble(NtDataObject ntDo) { return double.NaN; }
public Bitmap NtGetIcon(NtDataObject ntDo) { return null; }
public Bitmap NtGetBitmap(NtDataObject ntDo) { return null; }

As you can see, we use the dataTypeId to identify the type of object and then cast properly.

Conclusion
In most cases you can reference your data structure directly by the NtDataObject's dataItem member. But you can also create a new class type derived from NtDataObject and enhance it. No matter how - you will have to define the NtApplication interface properly to inform the NtTimeChartControl how to display your data. And please really understand the meaning of the dataTypeId member. This is crucial to not mix up your own data types and get into casting errors.

Back to Overview

Top Tutorials -> Data Objects © ?2016 Bassaly