Adding Graphic Information to a Data Point
You can add specific graphic information to a data point of a given data set. This information is stored in a dedicated object called a point information object. The information will be treated at the time the chart is drawn.
A point information object is an instance of the
IlvChartDataPointInfo class or one of its derived classes.
The
IlvChartDataPointInfo class allows you to draw the data point with a specific palette.
The
IlvChartDataGraphicInfo class allows you to draw any kind of graphic object next to the graphic representation of the data point. This graphic object can be used to define an annotation, put a marker on a given data point, and so on.
The
IlvChartGradientPointInfo class allows you to define a color gradient according to which data points will be drawn. The color of the point will be according to its value.
The point information objects defined for the data points of a given data set are managed by a dedicated object called a point information collection object. A point information object can be shared among different data points and a point information collection object can be shared among several data sets.
A point information collection object is represented by an instance of a subclass of the
IlvPointInfoCollection class. Three subclasses are predefined:
This class stores in arrays both the point information objects defined for the data points of a given data set and the indexes of the data points with which the point information objects are associated. The stored indexes are used to retrieve the point information object associated with a given data point.
This class stores in an array the point information objects defined for the data points of a given data set. The point information object associated with the data point at a given index in a data set is stored at the same index in the IlvPointInfoArray object that is associated with the data set.
Note: It is better to use an IlvPointInfoMap object rather than an IlvPointInfoArray object if you do not want to associate a point information object with each data point of a given data set. |
This class stores a unique point information object. It allows to associate the same point information object to all the data points of a data set.
A point information object can be associated with a data point at the level of a data set or at the level of a displayer. If the point information object is associated at the level of the data set, the point information object will be taken into account for each graphical representation of the data set that is performed in a chart. If the point information object is associated at the level of a displayer, it will be taken into account only in the graphical representation displayed by the displayer.
Notes: 1. Before adding a point information object to a data point at the level of a data set, you should set a point information collection object on the data set. 2. Before adding a point information object to a data point at the level of a displayer, you should set a point information collection object on the displayer. 3. If two point information objects are associated with a given data point (one at the level of the data set and one at the level of a displayer displaying the data set), only the point information object associated at the level of the displayer will be displayed by this displayer. |
Example
We can use the Temperatures Chart that was introduced in
General Architecture of the Charts Library as an example. Two sets of data representing the morning and afternoon mean temperatures are represented in different ways on the two charts.
Two Versions of the Temperatures Chart shows these two charts.
Two Versions of the Temperatures Chart
We want to customize how the data point corresponding to the highest afternoon temperature is displayed. We are going to add an annotation to the data point and display the data point with a specific palette. To do this, we need to add a point information object of the IlvChartDataGraphicInfo class to this data point.
The complete source code for this example can be found in the pointinfo.cpp file located in the $ILVHOME/samples/charts/userman/src directory. The following sections describe how to create and add the point information object to the data point.
Creating the Point Information Object
We want to display the text “Highest Afternoon Temperature” next to the data point corresponding to the highest afternoon temperature. We also want to display this data point with a specific palette. To do this, we create a point information object that stores an
IlvLabel object and the specific palette for displaying the data point.
IlvChartDataPointInfo* pointInfo = new IlvChartDataGraphicInfo(new IlvLabel(display, 0, 0, "Highest afternoon temperature"), 0, 0, IlvTopRight, display->getPalette(display->getColor("green"), display->getColor("white"))); |
The defined label will be drawn with its top right corner located at the offset (0, 0) from the data point with which the point information object will be associated.
Adding the Point Information Object to the Data Point
Next, we need to associate the point information object with the data point corresponding to the highest afternoon temperature. This data point is at the index 6 in the afternoon mean temperatures data set. We can add the point information object either at the level of the data set or at the level of the displayer.
To add the point information object at the level of the data set, use the following code:
// Set the point information collection object. dataSets[1]->setPointInfoCollection(new IlvPointInfoMap()); |
// Set the point information object. dataSets[1]->setPointInfo(6, pointInfo); |
where dataSets[1] corresponds to the afternoon mean temperatures data set.
The last line of code is equivalent to:
dataSets[1]->getPointInfoCollection()->setPointInfo(6, pointInfo); |
To add the point information object at the level of a displayer displaying the data set, use the following code:
// Set the point information collection object. chart1->getDisplayer(2)->setPointInfoCollection(dataSets[1], new IlvPointInfoMap()); // Set the point information object. chart1->getDisplayer(2)->getPointInfoCollection(dataSets[1]) ->setPointInfo(6, pointInfo); |
where chart1->getDisplayer(2) corresponds to the high-low bar displayer representing the afternoon mean temperatures data set in the first chart.
The two charts obtained once the point information has been added from these examples are shown in the following figures.
Point Information Object Associated with a Data Point at the Level of a Data Set shows the charts obtained when the point information object is added at the level of the data set.
Point Information Object Associated with a Data Point at the Level of a Displayer shows the charts obtained when the point information object is added at the level of the displayer.
Point Information Object Associated with a Data Point at the Level of a Data Set
Point Information Object Associated with a Data Point at the Level of a Displayer
You can see that when the point information object is associated at the level of the data set (
Point Information Object Associated with a Data Point at the Level of a Data Set), the stored label is displayed for all the graphical representations of the data set. Similarly, the stored specific palette is used to display the data point by all the displayers displaying the data set.
On the other hand, when the point information object is associated at the level of a displayer (
Point Information Object Associated with a Data Point at the Level of a Displayer), the stored label is displayed only by the displayer. Similarly, the stored specific palette is used to display the data point only by the displayer.
Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.