Chaozy
Chaozy

Reputation: 47

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

Upvotes: 1

Views: 1184

Answers (1)

Chaozy
Chaozy

Reputation: 47

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);

Upvotes: 1

Related Questions