Search code examples
javajfreechartlinegraph

How to customize x-axis label interval in JFreeChart?


I am currently using JFreeChart to display some data in a line graph. The labels on my x-axis (integers) are too dense, so I hope to display only the multiplies of 5 (1, 5, 10…). How can I achieve that?

Here is my x-axis


Solution

  • Thanks to trashgod. The NumberAxis does help in customizing the axis scale. I did use CategoryChart at first and the problem get solved when I switched to XYChart. Below is the snippet about using NumberAxis to change the x-axis scale.

    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickUnit(new NumberTickUnit(10));
    XYPlot plot = lineChart.getXYPlot();
    plot.setDomainAxis(xAxis);