In some situations, you may want to make use of gridlines and tick marks to improve the chart's readability. You have learned that you can control scaling with the Step property and MinorStep property. It is important to note that you can create and control gridlines and tick marks around major and minor units in the chart. These elements allow the user to easily detect when a particular value is plotted as a certain value or within a certain range.
Both the AxisX and AxisY objects list properties that allow you to set parameters that configure gridlines and tick marks on any axes of the chart. However, it is important to understand where gridlines and tick marks are positioned in the chart.
You must remember axis labels are placed in the major unit controlled by the Step property. Visual line attributesmay be applied to gridlines using the Grid property in conjunction with the supported Line class members(Color, Style, Width, EndCap and StartCap). The Gridlines property is used to show or hide the grid lines in the chart area, and the TickMark property is used to control tick marks. In the figure shown below it is easy to identify a step of 10, with tick marks placed outside the axis and Dash-Dotted blue gridlines:
Axis axis = chart1.getAxisY(); axis.setStep((short) 10); axis.setTickMark(TickMark.OUTSIDE); axis.setGridlines(true); axis.getGrid().setColor(new java.awt.Color(255, 0, 0));
|
Similarly, when you set a minor unit using the MinorStep property, labels will not be shown in this location but gridlines and tick marks can be set. For example, in the figure shown below, the MinorStep property has been set to 5 with minor tick marks shown as a "cross" and a solid gridline associated with the minor unit:
Axis axis = chart1.getAxisY(); axis.setMinorStep((short) 5); axis.setMinorTickMark(TickMark.INSIDE); axis.setMinorGridlines(true); axis.getMinorGrid().setColor(new java.awt.Color(255, 0, 0));
|
Interlaced Grids
In some cases interlaced gridlines greatly improve the chart's readability, as depicted in the following figure:

To achieve this effect, you need to set the chart's InsideColor property, the line's Color and the axis AlternateColor properties with the color you want for the interlaced stripes, plus set the Interlaced property supported in the Axis object. If you don't specify this color Chart FX will create a color based on the InsideColor property setting.
The code needed to acheive this is as follows:
chart1.setInsideColor(new java.awt.Color(192, 192, 192)); Axis axis = chart1.getAxisY(); axis.getGrid().setColor(new java.awt.Color(0, 0, 0)); axis.setAlternateColor(new java.awt.Color(255, 255, 255)); axis.setInterlaced(true);
|
|