skip to main content
Charts > Programmer's documentation > Developing with the JViews Charts SDK > Creating a Chart > Customizing a basic Cartesian chart
 
Customizing a basic Cartesian chart
The following steps illustrate how to customize the abscissa and ordinate scales, and how to add a legend to a chart.
To customize the abscissa scale:
*Configure the scale to display the labels associated with the category of the data sets. Enable the category display mode on the abscissa scale, so that numeric labels are replaced by the labels of the days:
 chart.getXScale.setCategory(tempDataSource.getDataSet(0),false);
The computation of the steps and substeps for a given scale is performed by a dedicated object called steps definition, which is set on the scale.
Two types of steps definition are available:
*numerical steps definition, which handles numeric steps values,
*time steps definition, which handles time values.
The steps definition type depends on the scale type: numeric steps definition for IlvScale.DEFAULT_SCALE and time steps definition for IlvScale.TIME_SCALE.
NOTE By default, a steps definition object is automatically set on a scale when it is created.
In this mode, the steps are determined according to the number of categories. The data set parameter is used to provide steps labels to the scale steps definition, and the false parameter is used to make steps appear at each category. You could have set the parameter to true to make steps appear between categories.
To customize the ordinate scale:
*Set the step and the substep units for the ordinate scale. Specify 5 as the step unit and 1 as the substep unit to have a major tick mark appear every five degrees and a minor tick mark every degree.
 chart.getYScale(0).setStepUnit(5.,1.);
The steps will be marked with a major tick mark and the substeps with a minor tick mark.
When a numeric scale is created, a numeric steps definition is set and the steps values are automatically computed. You do not want the values to be automatically computed, but rather manually set. The ordinate scale represents the temperature in degrees Celsius.
To add a legend:
*Add the legend with the ABSOLUTE constraint:
 IlvLegend legend = new IlvLegend(); legend.setLocation(250,270);
chart.addLegend(legend, IlvChartLayout.ABSOLUTE);
to have the legend displayed within the chart area.
A legend is an instance of the IlvLegend class (a JComponent subclass) that is associated with an IlvChart. A legend can be added to an IlvChart, but it is not mandatory. In this case, a legend can be added at several predefined positions (see the IlvChartLayout class) or at an absolute position, using its current location.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.