Charts > Using the Charts Library > Chart Basics > How Charts Work in Rogue Wave Views > Using the Component Classes in an IlvChartGraphic Object
 
Using the Component Classes in an IlvChartGraphic Object
To see how the component objects are used in a chart object, let’s take another look at our Temperatures Chart (see Figure 5.14). Instead of constructing this chart from an IlvCartesianChart object (see Creating a Simple Cartesian Chart), we are going to construct it from an IlvChartGraphic object, the base object that allows us to display a chart.
Figure 5.15 shows the component objects that are needed to display this chart. When we created the chart using an IlvCartesianChart object, we set the following objects by hand:
*The data sets
*The displayers
*The legend
If we use an IlvChartGraphic object instead of an IlvCartesianChart object, we must set the following objects as well:
*The projector object
*The coordinate information objects
*The scale displayer objects
The layout object does not need to be set since an instance is created by default when you create an IlvChartGraphic object.
To create our Temperatures Chart from an IlvChartGraphic object, we will again follow the basic steps presented in Creating a Simple Cartesian Chart. However, we must replace the step Creating a Cartesian Chart with the following series of tasks:
*Creating a Chart Graphic Object
*Creating and Setting the Projector
*Creating the Coordinate Information for the Abscissa
*Creating and Setting the Abscissa Scale Displayer
*Creating the Coordinate Information for the Ordinate
*Creating and Setting the Ordinate Scale Displayer
All the other tasks that are described in the paragraph Creating a Simple Cartesian Chart remain the same.
The complete source code of the example can be found in the chartgraphic.cpp file located in the $ILVHOME/samples/charts/userman/src directory.
Creating a Chart Graphic Object
To create a chart graphic object, use the following code:
IlvChartGraphic* chart = new IlvChartGraphic(display,
IlvRect(10, 10, 450, 300));
The IlvRect object passed as a parameter corresponds to the bounding box of the created chart.
Creating and Setting the Projector
Since the data to be displayed with our chart are expressed in Cartesian coordinates, the projector that is set is an instance of the IlvCartesianProjector class.
chart->setProjector(new IlvCartesianProjector(IlvCartesianProjector::IlvXRightYTop));
We indicate the orientation of the scales as a parameter: the abscissa scale is oriented toward the right of the screen and the ordinate scale is oriented toward the top. All orientations that keep the abscissa and the ordinate scale(s) orthogonal are possible.
Creating the Coordinate Information for the Abscissa
Use the following code to create the coordinate information for the abscissa:
IlvCoordinateInfo* abscissaCoordInfo
= new IlvCoordinateInfo(IlvAbscissaCoordinate);
The created coordinate information is associated with a coordinate. The type of this coordinate is passed as a parameter to the constructor used to create this coordinate information. By default, the minimum and maximum values that will be considered for the scale that represents this coordinate are automatically computed from the abscissa values of the data that have to be displayed by the created chart. This is done so that all the defined data can be displayed.
Creating and Setting the Abscissa Scale Displayer
To define the abscissa scale displayer, perform the following steps:
1. Create the displayer for the abscissa scale.
Since the data to be displayed with our chart are expressed in Cartesian coordinates, the object that is set to display the scale representing the abscissa values is an instance of the IlvRectangularScaleDisplayer class.
IlvRectangularScaleDisplayer* abscissaScale
= new IlvRectangularScaleDisplayer(abscissaCoordInfo,
chart->getPalette());
The coordinate information object associated with the coordinate that is represented by the abscissa scale is passed as a parameter to the constructor that creates the displayer for the abscissa scale. The palette that will be used to display the abscissa scale is set to the default palette of the created chart.
2. Set the displayer for the abscissa scale.
chart->setAbscissaScale(abscissaScale);
3. Customize the abscissa scale.
The format used for the values that are displayed next to the main graduations of a scale is set by default to "%.2f". Since the abscissa scale is used to represent integer values corresponding to the indexes of the days of the week (from 0 to 6), the format must be set to "%.0f" to avoid having the indexes of the days represented by floating values.
abscissaScale->setStepLabelFormat("%.0f");
The flag indicating whether the step labels must be drawn where the axes intersect is set by default to IlvFalse for a scale. Thus the label "0" for the first day of the week will not be drawn since the corresponding graduation is located on the abscissa scale at its intersection with the ordinate scale. To make this label appear, the flag must be set to IlvTrue.
abscissaScale->drawLabelOnCrossings(IlTrue);
Creating the Coordinate Information for the Ordinate
To create the coordinate information for the ordinate, use the following code:
IlvCoordinateInfo* ordinateCoordInfo
= new IlvCoordinateInfo(IlvOrdinateCoordinate);
The created coordinate information is associated with a coordinate. The type of this coordinate is passed as a parameter to the constructor used to create this coordinate information. By default, the minimum and maximum values that will be considered for the scale that represents this coordinate are automatically computed from the ordinate values of the data that have to be displayed along this scale. This is done so that all the defined data that have to be displayed along this scale can be displayed.
Creating and Setting the Ordinate Scale Displayer
To define the ordinate scale displayer, perform the following steps:
1. Create the displayer for the ordinate scale.
IlvRectangularScaleDisplayer* ordinateScale
= new IlvRectangularScaleDisplayer(ordinateCoordInfo,
chart->getPalette());
Just as with the abscissa scale, the coordinate information object associated with the coordinate that is represented by the ordinate scale is passed as a parameter to the constructor that creates the displayer for the ordinate scale. The palette that will be used to display the ordinate scale is set to the default palette of the created chart.
2. Set the displayer for the ordinate scale.
chart->addOrdinateScale(ordinateScale);
3. Customize the ordinate scale.
The flag indicating whether the step labels must be drawn where the axes intersect is set by default to IlvFalse for a scale. Thus the label "8" for the minimum temperature value that is displayed will not be drawn since the corresponding graduation is located on the ordinate scale at its intersection with the abscissa scale. To make this label appear, the flag must be set to IlvTrue.
ordinateScale->drawLabelOnCrossings(IlTrue);
At this point, we have now completed creating our Cartesian chart from an IlvChartGraphic object. The chart we obtain is the same as the one shown in Figure 5.7. You can readily see the difference in using an IlvChartGraphic object instead of using an IlvCartesianChart object. Many more lines of code were required to instantiate the same chart object that we obtained by using a single line of code:
IlvChartGraphic* chart = new IlvCartesianChart(display,
IlvRect(10, 10, 450, 300));

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.