Y Axis AutoRange and min value

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Kev Palfreyman

Y Axis AutoRange and min value

Post by Kev Palfreyman » Sat Oct 26, 2002 6:36 pm

Hello,

I'm new to JFreeChart and evaluating it to decide if we should buy.

I have a TimeSeriesChart that I'm trying to customise. I have the X axis as needed (for now at least), but I'm having trouble with the Y axis.

The effect I want is to use AutoRange, but with a fixed minimum of zero.
i.e. I want the Y axis to resize as necessary, but never to show anything below zero (and unlimited positive).

I tried:
NumberAxis yAxis = new VerticalNumberAxis("");
yAxis.setLowerMargin(0.00); // percentage to be added to lower part of axis when recalculating
yAxis.setAutoRange(true);
yAxis.setMinimumAxisValue(0.0); // this call breaks it - the line goes out of view off the top
yAxis.setAutoRangeMinimumSize(new Integer(5));


I start off with two data points, both zero.
This gives me a starting axis of 0.0 -> 1.0, which seems OK, but when I dynamically add data greater than 1.0 the plot is off the scale - no resize of the axis. If I remove the call to setMinimumAxisValue, then it shows some negative y axis which is not what I want.

Please help - it looks like a great product, but I can't get past this stumbling block.

Thanks,

Kev

Dave Gilbert

Re: Y Axis AutoRange and min value

Post by Dave Gilbert » Mon Oct 28, 2002 10:11 am

Hi Kev,

The default setting for the axis is to show all of your data (i.e. the axis range is automatically calculated to include the smallest to largest values, plus a small margin at each end to make sure your data isn't displayed hard up against the edge of the plot).

There is a method in the NumberAxis class that controls whether or not zero is included in the auto-range: setAutoRangeIncludesZero(boolean). I think the default is false for a time series chart.

Don't call setMinimumAxisValue(...). This is used to set a manual axis range, and switches off the auto-range calculation.

One other setting controls what happens when zero falls within the 'margin' of the axis range - should you leave the margin at full size (default 5%) and include negative values, or truncate the margin at zero? Use setAutoRangeStickyZero(boolean) in the NumberAxis class. My guess is that you will want to set this to true.

Regards,

DG.

Locked