I'm trying to create a plot using JFreeChart, and I'm having trouble configuring the axes. My requirements for my axes:
- Set a fixed range: i.e. 0 to 1000
- Initialize the graph with ticks at every X units, i.e. let's say every 50 units.
- If the user increases the size, or zooms in, recompute and add new ticks (like the default auto tick unit selection functionality).
- No need to worry about decreasing chart size, the chart size minimum is the initial size.
The problem I'm facing is that defining my own tick intervals with NumberAxis.setTickUnit() disables the auto tick unit selection, so scaling up the graph no longer adds new ticks. But if I don't manually set the ticks, it gives me a different tick unit order (i.e. every 100 units).
Here's my code:
// this doesn't scale up properly, won't add new tick marks
NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
xAxis.setRange(0, X);
xAxis.setAutoRange(false); // stop graph from resizing axis to data
xAxis.setTickUnit(new NumberTickUnit(Y)); // disables auto tick unit selection
So this gives a fixed range from 0 to X, with ticks at every Y units. No new ticks when I increase the size. How can I maintain the auto tick selection when I increase size?