Problem with 1.5 Example Source DualAxisDemo2.java

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dgarratt
Posts: 8
Joined: Mon Aug 19, 2019 7:29 pm
antibot: No, of course not.

Problem with 1.5 Example Source DualAxisDemo2.java

Post by dgarratt » Fri Sep 27, 2019 5:18 pm

If you amend this example code so that you only have 1 value in each axis

so that you have :-

private static XYDataset createDataset1() {

TimeSeries s1 = new TimeSeries("Random Data 1");
s1.add(new Month(2, 2016), 181.8);

TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);

return dataset;

}

and likewise for createDataset2 you end up with some wierd values on the axis scales.

4.296E2 for example

Any ideas ?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Problem with 1.5 Example Source DualAxisDemo2.java

Post by david.gilbert » Sat Sep 28, 2019 1:19 pm

I see this also. What is happening is that the range for the axes is determined by looking at the minimum and maximum data values. In this case, there is just a single value (429.6) so JFreeChart has to decide what should be the minimum and maximum values on the axis. It does this by looking at an attribute 'autoRangeMinimumSize' - the default is very small, and it doesn't seem to interact so well with the tick label format. One workaround is that you can override the autoRangeMinimumSize as follows (choose some value that is appropriate for your data):

Code: Select all

        NumberAxis axis1 = (NumberAxis) plot.getRangeAxis();
        axis1.setAutoRangeMinimumSize(1.0);
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

dgarratt
Posts: 8
Joined: Mon Aug 19, 2019 7:29 pm
antibot: No, of course not.

Re: Problem with 1.5 Example Source DualAxisDemo2.java

Post by dgarratt » Sat Sep 28, 2019 2:42 pm

Yes that seems to have fixed the problem.

Many thanks for such a quick response - most appreciated.

Dave

Locked