Charts > Using the Charts Library > Data Handling > Handling Data Storage > Adding Data Sets to Be Displayed by a Chart
 
Adding Data Sets to Be Displayed by a Chart
To display a data set within a given chart, the data set must be added to the chart data object that is set on the chart. You can do this in two ways:
*Set the data sets for the chart data object that is created by default and set on the chart.
*Create your own chart data object, set the data sets for this chart data object, and then set the chart data object for the chart.
Examples
In the following examples, we will show you how to add two data sets, an IlvChartPointSet data set and an IlvChartYValueSet data set, to a chart object.
IlvChartDataSet* dataSets[2];
//== Creating the IlvChartPointSet data set and fill it with data.
dataSets[0] = new IlvChartPointSet();
dataSets[0]->addPoint(IlvDoublePoint(0.5, 1.0));
dataSets[0]->addPoint(IlvDoublePoint(1.2, 2.3));
dataSets[0]->addPoint(IlvDoublePoint(1.6, 3.1));
 
//== Creating the IlvChartYValueSet data set and fill it with data.
dataSets[1] = new IlvChartYValueSet();
dataSets[1]->addPoint(IlvDoublePoint(0, 1.2));
dataSets[1]->addPoint(IlvDoublePoint(1, 3.1));
dataSets[1]->addPoint(IlvDoublePoint(2, 4.6));
The first example will show you how to add the data sets to the default chart data object. The second example will show you how to add the data sets to your own chart data object.
Adding the Data Sets to the Default Chart Data Object
The chart data object that is set on a given chart object to manage the data sets it displays is obtained by using the IlvChartGraphic::getData method.
You can use the following code to add the data sets directly to the chart data object that has been created by default and set for the chart object:
chart->getData()->addDataSet(dataSets[0]);
chart->getData()->addDataSet(dataSets[1]);
Or more simply, you can add the two data sets at the same time:
IlUInt dataSetsCount = 2;
chart->getData()->setDataSets(dataSetsCount, dataSets);
Adding Data Sets to Your Own Chart Data Object
To use your own chart data object to manage the data sets to be displayed by a given chart object, do the following:
1. Set the data sets directly for your chart data object.
IlvAbstractChartData* myChartData = new IlvMemoryChartData();
myChartData->addDataSet(dataSets[0]);
myChartData->addDataSet(dataSets[1]);
2. Set this chart data object for the chart object.
chart->setData(myChartData);
Note: You can use whatever chart data object you want as long as it is a derived object of the IlvAbstractChartData class.

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.