Autorange on ValueAxis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
GraemeK
Posts: 7
Joined: Wed Jan 04, 2017 5:16 am
antibot: No, of course not.

Autorange on ValueAxis

Post by GraemeK » Thu Jan 12, 2017 9:57 pm

Hi folks,

I have a situation where a dataset coming from the database contains only zeros (price on the value axis) for the values for each day of a month (the category axis).

In the situation where all the values are zero, I notice that on the bar chart 0E0 is rendered in the middle of the value axis with 5E-9 at the top and -5E-9 at the bottom. It doesn't look quite right.

Is there a way to set a default range in this case between 0 and 20, for example.

Normally a chart would render between 0 and some arbitrary value... I'm not sure I know what the maximum can be.

I figured I could set the auto range something like this:

ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setDefaultAutoRange( new Range( 0, 20 ) );

But this (and others) don't appear to work in the zero-case scenario above.

Many thanks.

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

Re: Autorange on ValueAxis

Post by david.gilbert » Fri Jan 13, 2017 1:52 pm

The defaultAutoRange attribute is only used when there is no data in the dataset.

Where there is data, but it has a constant value (such as zero) the measured range has length zero ... for this you can use the setAutoRangeMinimumSize(double) method to specify what the actual length should be. It might not do exactly what you want though, since if you specify a minimum length of 20 it will result in a range from -10 to 10 for the case where the dataset contains all zeros.
David Gilbert
JFreeChart Project Leader

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

GraemeK
Posts: 7
Joined: Wed Jan 04, 2017 5:16 am
antibot: No, of course not.

Re: Autorange on ValueAxis

Post by GraemeK » Fri Jan 13, 2017 3:05 pm

Thanks David,

I thought it might not look exactly right but on reflection it looks perfect now! Thanks!

Graeme.

Locked