Zooming in x, autoranging in y

Discussion about JFreeChart related to stockmarket charts.
Locked
JGoodwin
Posts: 27
Joined: Thu Sep 06, 2007 3:19 am
Location: Boston USA

Zooming in x, autoranging in y

Post by JGoodwin » Sun Jun 03, 2012 6:28 pm

I have various financial charts, all XYPlots, all using a DateAxis for the x-axis. They may have several
datasets and several axes, for example an OHLC and one or two moving-averages mapped onto a
NumberAxis (price axis) on the left and a trading volume dataset, mapped onto another number axis
(volume axis) on the right.

When the chart is first displayed, autoranging does what I want, "shrink-wrapping" the whole chart,
so the DateAxis is scaled to the time interval from the earliest to the most recent datapoint, and
the Y axis is scaled to fit the min/max Y values found over that interval, plus a bit of margin.

(Incidentally I also want to show the volume in the lower 25% and the prices in the upper 75% but
I think I can get that with the margin parameters on the plot, so I think that's not a problem.)

Then the user zooms the chart, by dragging out a zoom rectangle. Now what I call "normal" zoom
behavior is that each axis is independently rescaled, so that the extent of the drag-rectangle in
that dimension (x or y) becomes the extent of the entire visible portion of the chart.

That's what i want in x (time). But in y (price, volume axes) what I want is that the y-axes rescale
to shrink wrap the new range of data captured. In other words, the Y-extent of the drag rectangle
is ignored; the max/min Y values over the visible time-extent are computed, and the Y axis is
scaled to fit that to the chart.

And panning: when the user pans the chart, I want the pan to shift the visible portion of the x axis
left or right, without rescaling it, and then the Y axes to autorange again, "shrink wrapping" the
Y data that falls into the new time-window.

What's the smartest way to set this up? I've read the code and the manual, a lot, and gotten rather
tangled up.

Thanks
Jim Goodwin

JGoodwin
Posts: 27
Joined: Thu Sep 06, 2007 3:19 am
Location: Boston USA

Re: Zooming in x, autoranging in y

Post by JGoodwin » Tue Jun 05, 2012 2:27 pm

Autoranging is designed to work through the findRangeBounds(XYDataset) method
of the renderer associated with the Dataset.

For XYLineAndShapeRenderer this works fine. For HighLowRenderer, it fails.

The difference is that XYLineAndShapeRenderer returns the range of Y values found
in the dataset WITHIN THE CURRENT (i.e. VISIBLE INTERVAL) on the domain axis.
HighLowRenderer returns the range over the entire dataset, ignoring the current
interval.

This seems like a bug to me; is there some rationale I'm missing? Are renderers
specified in general to be sensitive to the current interval, or not to be, or is
there some logic to why some do and some don't?

What would be the best workaround? I want a renderer to show OHLC bars
for an OHLC dataset.

Notes on the code:

In both cases control flows from NumberAxis.autoAdjustRange()
and eventually invokes findRangeBounds(XYDataset). But XYLineAndShapeRenderer
inherits this from AbstractXYItemRenderer, whereas HighLowRenderer overrides
it, and uses routines in DatasetUtilities that ignore current x-axis intervals. See
DatasetUtilities.iterateRangeBounds() 2nd of 3 cases lines 1267-1278,
JFreeChart 1.0.14

What is the spec for findRangeBounds? To be sensitive to current interval or not,
or some other kind of rule?

I haven't yet looked to see if the Candlestick renderer has the same problem.

Thanks
Jim

autorange
Posts: 2
Joined: Fri Aug 24, 2012 4:34 pm
antibot: No, of course not.
Location: Hong Kong

Re: Zooming in x, autoranging in y

Post by autorange » Fri Aug 24, 2012 4:59 pm

JGoodwin, did you ever find a solultion for this?

I'm having the same issue. Basically I'd like the Y range (NumberAxis) to auto adjust to the min/max visible data points after a domain zoom. I'm using a CombinedDomainXYPlot with a DateAxis and multiple subplots using NumberAxis.

I'm only a new user so I have no idea if it's supposed to be possible, but there's a bug as suggested, or whether it's a simply not implemented. Per the first post below, it wasn't a feature many years ago, but not sure if it was added at some point.

I've searched a lot and could only find the following threads:

viewtopic.php?f=3&t=11469&p=33108

http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=21909

http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=23771

autorange
Posts: 2
Joined: Fri Aug 24, 2012 4:34 pm
antibot: No, of course not.
Location: Hong Kong

Re: Zooming in x, autoranging in y

Post by autorange » Fri Aug 24, 2012 5:53 pm

After stepping through the code, this appears to be not yet implemented, in my case at least.

My dataset is a TimeSeriesCollection (instance of XYRangeInfo), and so TimeSeriesCollection.getRangeBounds is used rather than DatasetUtilities.iterateRangeBounds() (called on line 924 of DatasetUtilities).

TimeSeriesCollection.getRangeBounds doesn't use the xRange parameter that is passed to it and there is a specific comment in the code on line 682:

Code: Select all

// FIXME: Here we are ignoring the xRange
Time to sort out a workaround : )

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

Re: Zooming in x, autoranging in y

Post by david.gilbert » Thu Aug 30, 2012 5:41 am

Originally none of the range finding code took the current x-axis range into account when determining the y-axis range. That's generally a limitation, so I started to implement this renderer by renderer. That work has never been completed, so you will see some renderers supporting the feature and others not. Eventually I'd like to make them all consistent.
David Gilbert
JFreeChart Project Leader

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

Locked