AutoRange and Zoom
-
- Posts: 4
- Joined: Tue Feb 05, 2008 5:41 pm
AutoRange and Zoom
Hello there! I'm currently using JFreeCharts to plot some Times Series data, and have noticed that when I zoom into the chart and then zoom back out, the Y-axis ranges I specify for the chart are no longer adhered too. It's almost as if autorange gets set back equal to true even though I explicitly turned it off. Any ideas on what could be causing this?
Thanks!
Chuck
Thanks!
Chuck
-
- Posts: 3
- Joined: Wed Feb 27, 2008 7:00 pm
An Additional Problem
Although my Y data ranges from 10 to 50, "Auto Range" consistently sets the minimum Y axis value at 0. This only happens when all of the Y data is > 0. The opposite happens when all the Y data is < 0: the maximum Y axis value is set to 0, despite the data only containing values from -100 to -30. Everything seems fine if the Y data contains both positive and negative values. The X axis works fine in any case. I'm not setting any axis ranges. I downloaded the latest version of JFreeChart (1.0.9) and JCommon (1.0.12) to see it that fixed the problem. It didn't.
Did you try calling
Code: Select all
axis.setAutoRangeIncludesZero(false);
I was stuck with something like this, I ended up doing something that kind of works. It has the range axis around 0 to 130000, but when you zoom out it goes to 0 to 131750, but it's close enough and you can't really tell.
I know you're not using this type of plot, but something to lead you in the right direction. I remember there being a problem like this back in 1.0.2 or something, and I ended up just hacking the class to fix it.
Good luck.
plot.getRangeAxis().setRange(0, 130000);
((NumberAxis)plot.getRangeAxis()).setAutoRangeMinimumSize(130000);
((NumberAxis)plot.getRangeAxis()).setRangeType(RangeType.POSITIVE);
I know you're not using this type of plot, but something to lead you in the right direction. I remember there being a problem like this back in 1.0.2 or something, and I ended up just hacking the class to fix it.
Good luck.
plot.getRangeAxis().setRange(0, 130000);
((NumberAxis)plot.getRangeAxis()).setAutoRangeMinimumSize(130000);
((NumberAxis)plot.getRangeAxis()).setRangeType(RangeType.POSITIVE);
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: AutoRange and Zoom
The way that zooming is implemented, when you "unzoom" the axes ranges do just return to the auto-range values (so that all data is visible on the chart). It would of course be nice to be able to specify the default base ranges for the axes, and have the "unzoom" behaviour just restore the defaults. I'll add it to the to-do list.dorseywright wrote:...and have noticed that when I zoom into the chart and then zoom back out, the Y-axis ranges I specify for the chart are no longer adhered too. It's almost as if autorange gets set back equal to true even though I explicitly turned it off.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 3
- Joined: Wed Feb 27, 2008 7:00 pm
-
- Posts: 1
- Joined: Thu Oct 30, 2008 10:09 am
Is it in the actual release possible to set a default base for a Axis?The way that zooming is implemented, when you "unzoom" the axes ranges do just return to the auto-range values (so that all data is visible on the chart). It would of course be nice to be able to specify the default base ranges for the axes, and have the "unzoom" behaviour just restore the defaults. I'll add it to the to-do list.
Re: AutoRange and Zoom
I see this is stil an issue with version 1.0.13. I wonder is there a way we can override this "unzoom" behavior so that it will set the range as "what is before zoom". Basically what jfree method is called when you unzoom or drag the mouse up?
Re: AutoRange and Zoom
The implementation of MouseListener is in org/jfree/chart/ChartPanel.javashil wrote:Basically what jfree method is called when you unzoom or drag the mouse up?
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: AutoRange and Zoom
If you unzoom, i. e. if either the x or the y coordinate of the point at which the mouse is released is smaller that the x or y coordinate of the point at which the zoom was started, the restoreAutoBounds() method of ChartPanel is called. If the Plot implements Zoomable, zoomable.zoom[Range/Domain]Axes(double factor, PlotRenderingInfo info, Point2D source) is called with a factor of 0.0 which in turn calls ValueAxis.resizeRange(double factor) with the same factor which, for a factor of =< 0.0, calls ValueAxis.autoAdjustRange().shil wrote:I see this is stil an issue with version 1.0.13. I wonder is there a way we can override this "unzoom" behavior so that it will set the range as "what is before zoom". Basically what jfree method is called when you unzoom or drag the mouse up?
if you want to change the unzooming behaviour, I would recommend to modify the autoAdjustRange() method of the NumberAxis/DateAxis classes. The required modifications depend on what behaviour you want to have.
In this thread, it was desired that a predefined range was restored upon unzooming. The suggested solution (add a flag that indicates whether the default auto range should be restored in autoAdjustRange() or (the present behaviour) a range that makes all data items visible, check that flag the autoAdjustRange, and if is true, simply restore the default auto range. At present, the defaultAutoRange is only used if the dataset is empty) should be easy to implement.
If you need more advanced features, such as a tracking of all zoom operations (as outlined , and a stepwise unzooming, things can get complicated. it is probably not too difficult to implement such a behaviour, but it can be difficult to figure out what the users wants to achieve if an "unzoom" is triggered. Both unzoom methods (track the zoom operations and go back stepwise upon unzoom or simply restore a predefined range) can be useful. Combinations of mouse operations and key presses could do it but that is not really intuitive.
I have thought about delegating the mouse event handling from the ChartPanel class to pluggable "ChartMouseTool" classes than can be activated or deactivated by pressing icon buttons in a button bar and that offer more modular mouse event handling: one tool for zooming, one for panning, one for modifying annotations, one for markes, one for changing texts of the chart (textTitle, axis labels...) without increasing the size and complexity of the ChartPanel class with every added functionality... but thats something big and will have to wait.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: AutoRange and Zoom
In fact, I just implemented this feature for a client, and it will find its way into Subversion some time next week.paradoxoff wrote:I have thought about delegating the mouse event handling from the ChartPanel class to pluggable "ChartMouseTool" classes than can be activated or deactivated by pressing icon buttons in a button bar and that offer more modular mouse event handling: one tool for zooming, one for panning, one for modifying annotations, one for markes, one for changing texts of the chart (textTitle, axis labels...) without increasing the size and complexity of the ChartPanel class with every added functionality... but thats something big and will have to wait.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: AutoRange and Zoom
Hi skunk,
Thanks for your tips. I am able to control unzoom behavior by overriding restoreAutoDomainBounds() in CharPanel.
Thanks for your tips. I am able to control unzoom behavior by overriding restoreAutoDomainBounds() in CharPanel.
Code: Select all
public class MyChartPanel extends ChartPanel
{
public MyChartPanel(JFreeChart chart)
{
super(chart);
}
@Override
public void restoreAutoDomainBounds()
{
super.restoreAutoDomainBounds();
// Set your desired range
myDomainAxis.setRange(desiredRange);
myRangeAxis.setRange(desiredRange);
}
}
Re: AutoRange and Zoom
Glad it helped. Thanks for sharing the code so others can benefit.