Axis Formatting

Formatting a numerical axis is as simple as setting any of the pre-defined axis formats in Chart FX for Java using the Format property supported by the ValueFormat class. For example, if you want scientific notation in the primary Y-axis, your code should look like this:


chart1.getAxisY().getLabelsFormat().
setFormat(AxisFormat.SCIENTIFIC);

Please make sure you check the Format property on the Javadoc API for more information on any pre-defined formats supported by Chart FX for Java.

User-Defined Formats

Because Chart FX supports dates as well as numbers in an axis, you can define your own formats by creating a mask that will instruct Chart FX for Java how to format and display labels in the selected axis. For example, if you set dates for the X-axis, you may create the following custom format:


chart1.getAxisY().getLabelsFormat().
setCustomFormat("mm/dd/yy");

Note:When setting the CustomFormat property to a specific decimal value, any settings configured using the Decimals property will be ignored.

Logarithmic Scales

When plotting large numbers, Chart FX for Java supports independent logarithmic scales on any of the axes (Primary, Secondary Y and X when used in a numerical sense). You may have Log-Log, Linear-Log or Log-Linear scales.

To set a Logarithmic scale for any of the Chart FX for Java numerical axes you can use the LogBase property. This property will set a logarithmic scale for a numerical axis and recalculate the values as powers equal to the setting of this property. For example, if you want to set the Y-axis to be logarithmic with base 10 your code should look like the following:


chart1.getAxisY().setLogBase((short) 10);

Manipulating Dates and Times in a Categorical Axis

You have learned that Chart FX for Java provides a means of formatting the axis labels to display date/time format rather than a number format through the ValueFormat class Format property.

After you have set the format of the axis you can then use the Min, Max, and Step properties to modify the display.


Axis axis = chart1.getAxisX();
axis.getLabelsFormat().setFormat(AxisFormat.DATE);

This additional sample code shows how to display time labels for a period of 2 days with step set to 1 hour:


Axis axis = chart1.getAxisX();
axis.getLabelsFormat().setFormat(AxisFormat.TIME);
axis.setMin(0);
axis.setMax(2);
axis.setStep(1/24);