0
votes

I have an XYPlot displaying points and lines. The points are created randomly so the chart will be different every time I launch the application.
With my current example, I've got the following TickUnit :
- Y axis : 1 2 3 4 5 6 ...
- X axis : 0.2 0.4 0.6 0.8 ...

I'm trying to get current TickUnit but it returns "size=1" for both axis :

NumberAxis range1 = (NumberAxis)plot.getRangeAxis();
NumberTickUnit ntu1 = range1.getTickUnit();
System.out.println(""+ range1.getTickUnit().toString());

NumberAxis range2 = (NumberAxis)plot.getDomainAxis();
NumberTickUnit ntu2 = range2.getTickUnit();
System.out.println(""+ range2.getTickUnit().toString());    

Any idea how I can get 0.2 for X axis ?
I'd like to get these values so that I can add an annotation over a line at an appropriated distance.

1
Cross-posted here. - trashgod

1 Answers

1
votes

The documentation mentions:

Note: if the autoTickUnitSelection flag is true the tick unit may be changed while the axis is being drawn, so in that case the return value from this method may be irrelevant if the method is called before the axis has been drawn.

Try calling the method after the graph is displayed, e.g. using SwingUtilities.invokeLater().