In This Topic
In the context of NOV Chart, the term Data Series refers to the array of values formed by the property values for a specific data point property. For example consider the following example:
Data Series Example |
Copy Code
|
NLineSeries lineSeries = new NLineSeries();
lineSeries.DataPoints.Add(new NLineDataPoint() {
Value = 10,
X = 50
});
lineSeries.DataPoints.Add(new NLineDataPoint() {
Value = 20,
X = 70
});
lineSeries.DataPoints.Add(new NLineDataPoint() {
Value = 30,
X = 90
});
|
Getting Data Series
You can get the values contained inside a data series via the GetDataSeries<TValue> method. The TValue passed as argument is the type to which you want the values converted. You will typically use the type of the respective data series - for example double for Value, X and other numeric values, string for Label etc. The following example gets the X data series of the line series created in the previous example:
Getting Data Series |
Copy Code
|
double[] xvalues = lineSeries.DataPoints.GetDataSeries<double>("X");
|
For the purpose of using the chart values in Formulas, you can also get the data series a variant array via the GetDataSeriesVariant method, as shown in the next example:
Getting Data Series as Variant |
Copy Code
|
NVariant valuesVar = barSeries.DataPoints.GetDataSeriesVariant("Value");
NFormulaCalculator fxCalc = new NFormulaCalculator();
fxCalc.Variables.Add("values", valuesVar);
fxCalc.Formula = "AVG(values)";
double average = (double)fxCalc.Evaluate();
|
Setting Data Series
The importing of data series is performed by a set of SetDataSeries methods, that have the following features in common:
- contain a mapping between the source of import and the target data point series. The target data point series are specified by a string, which is the name of the data points property in which the source values must be imported (for example: "Value", "X", "Label" etc.).
- have an optional updateMode parameter of type ENDataPointsUpdateMode that specifies how the data point collection should be updated to accommodate the data series values. Possible values are:
- Recreate - Clears the data points collections and then creates a new data point for each data series value. (the default, if not specified).
- Append - Do not clear the collection and just append a new data point for each data series value.
- Update - Update the values of the existing data points starting from zero. Do not create new or delete existing data points.
- UpdateAndResize - Update the values of the existing data points starting from zero. Creates new data points if data series have more values, and delete data points if data series have fewer values.
Following is a summary of the SetDataSeries methods:
-
Import from INIterable<TValue>
The following example imports the values of a list of doubles into the Values data series:
Import from INIterable<TValue> |
Copy Code
|
NList<double> values = new NList<double>();
values.Add(10);
values.Add(20);
values.Add(30);
barSeries.DataPoints.SetDataSeries<double>(values, "Value");
|
-
Import from IEnumerable<TValue>
The following example imports the values of an array of doubles into the Values data series:
Import from IEnumerable |
Copy Code
|
double[] values = new double[] { 10, 20, 30 };
barSeries.DataPoints.SetDataSeries(values, "Value");
|
-
Import from multiple IEnumerable<TValue> sources
The following example imports three arrays into the Value, XValue and Label data series:
Import from multiple IEnumerable sources into multiple data series |
Copy Code
|
double[] values = new double[] { 10, 20, 30 };
double[] xvalues = new double[] { 20, 34, 45 };
string[] labels = new string[] { "apples", "oranges", "bananas" };
// import multiple data series
NPointSeries pointSeries = new NPointSeries();
pointSeries.DataPoints.Import(new NKeyValuePair<IEnumerable, string>[] {
new NKeyValuePair<IEnumerable, string>(values, "Value"),
new NKeyValuePair<IEnumerable, string>(xvalues, "X"),
new NKeyValuePair<IEnumerable, string>(labels, "Label")
});
|
-
Import of multiple columns from a NDataTable source
The following example creates an in-memory data table and imports several columns into multiple data series:
Import from multiple data table columns into multiple data series |
Copy Code
|
// create a table with random data
NMemoryDataTable table = new NMemoryDataTable(
new NFieldInfo("Y", typeof(double)),
new NFieldInfo("X", typeof(double)),
new NFieldInfo("Label", typeof(string))
);
Random rnd = new Random();
for (int i = 0; i < 10; i++)
{
table.AddRow();
table.SetValue(i, "Y", rnd.Next(0, 100));
table.SetValue(i, "X", rnd.Next(0, 100));
table.SetValue(i, "Label", "Label: " + i.ToString());
}
// import multiple data series
NLineSeries lineSeries = new NLineSeries();
lineSeries.DataPoints.Import(table,
new NKeyValuePair<string, string>[] {
new NKeyValuePair<string, string>("Y", "Value"),
new NKeyValuePair<string, string>("X", "X"),
new NKeyValuePair<string, string>("Label", "Label")
});
|
-
Import from NDbDataReader
The following example imports data from a DB Table:
Import from NDbDataReader |
Copy Code
|
// created random data series
NDbConnection connection = null;
try
{
// try open the connection
connection = NDbConnection.Open(ENDbConnectionType.Odbc, "DSN=Extreme");
NDbDataReader dataReader = connection.ExecuteReader("SELECT * FROM SALES");
pointSeries.DataPoints.Import(dataReader,
new NKeyValuePair<string, string>[] {
new NKeyValuePair<string, string>("TotalPrice", "Value"),
new NKeyValuePair<string, string>("SaleDate", "X")
});
}
catch (Exception ex)
{
NMessageBox.Show(ex.Message, "Data Import Error");
}
finally
{
// close the connection
if (connection != null)
{
connection.Close();
}
}
|