Simple question about display of axis range

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jahjeremy
Posts: 31
Joined: Tue Sep 25, 2012 2:49 am
antibot: No, of course not.

Simple question about display of axis range

Post by jahjeremy » Thu Oct 09, 2014 11:58 pm

Hi,

I have what is hopefully a simple question about the display area of a chart when explicitly setting an axis range.

I create an axis like this in the usual way:

Code: Select all

NumberAxis xAxis = new NumberAxis("X Axis");       
xAxis.setRange(new Range(0.0, 2.0), true, true);        
plot.setDomainAxis(xAxis);
So I'm trying to set an explicit range between 0 and 2.0 (just for example).

Then I print out the upper and lower bounds on the axis from debug code and they are 0.0 and 2.0 respectively.

Code: Select all

System.out.println("xAxis range: " + xAxis.getRange().getLowerBound() + " " + xAxis.getRange().getUpperBound());
And that prints out:

xAxis range: 0.0 2.0

So far so good. This range looks correct from what I set.

But when I actually show the chart, the range that actually displays is truncated to some lower value which looks to be around 1.6 or so.

Curiously enough, when I use the ChartPanel's right click menu to reset the zoom, it also uses this (arbitrary?) value as the upper bound on the axis.

My question is basically, why would the chart do this and not display the entire range if I have set it explicitly on the XYPlot's axis? Is there some behind the scenes interaction with the tick settings that might do this?

And how can I force a chart to display exactly the range I have set on the axis rather than trying to do something clever which is not what I want? 8)

If I play around with other values, sometimes it doesn't do this and displays the full range. The problems with display of range seem to occur when the total range of the axis is small like 2.0 or less. For larger ranges, it seems to behave more reasonably in this respect.

Any tips appreciated.

(If you need more thorough example code to show the problem from scratch, I can try to provide it.)

Thanks.

--Jeremy

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

Re: Simple question about display of axis range

Post by david.gilbert » Fri Oct 10, 2014 6:00 am

When you set the axis range manually, the 'autoRange' flag is set to false and the axis bounds will never be changed by JFreeChart. Perhaps somewhere later in your code you call setAutoRange(true)? If not, there must be a bug in JFreeChart...if you can supply an example that reproduces it, I will fix it quickly.
David Gilbert
JFreeChart Project Leader

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

jahjeremy
Posts: 31
Joined: Tue Sep 25, 2012 2:49 am
antibot: No, of course not.

Re: Simple question about display of axis range

Post by jahjeremy » Mon Oct 13, 2014 10:42 pm

Okay, I see what you're saying. But actually setting minimum sizes when auto ranging also doesn't always give me what I want.

Working on test code now....

Locked