Getting the zoom range

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

Getting the zoom range

Post by Bill Zahavi » Mon Dec 23, 2002 1:51 am

After zooming I would like to have the starting point, ending point and number of points of the zoomed image. How do I get them?

David Gilbert

Re: Getting the zoom range

Post by David Gilbert » Mon Dec 23, 2002 9:54 am

After zooming, all that happens is the range on each axis is adjusted. You can find out the current range for each axis using the getRange() method in the ValueAxis class:

XYPlot plot = myChart.getXYPlot();
ValueAxis axis = plot.getDomainAxis();
Range range = axis.getRange();

The data in your dataset is not altered in any way. To find out how many points are displayed on the chart, you would have to iterate through all the data items and check whether or not they fall within the current axis ranges.

Regards,

Dave Gilbert

Bill Zahavi

Re: Getting the zoom range

Post by Bill Zahavi » Mon Dec 23, 2002 4:48 pm

This appears to get me close. However sometimes either the first or last point are not included.

double visible_low_point = io_graph.chart.getXYPlot().getDomainAxis().getRange().getLowerBound();
double visible_hi_point = io_graph.chart.getXYPlot().getDomainAxis().getRange().getUpperBound();
System.out.print("visible number of points: " + view + "\n");
int first_zoomed = (int)((((visible_low_point - total_ios_graph_low_point)/total_ios_graph_range) * my_x)+.99);
System.out.print("first zoomed point: " + first_zoomed + "\n");
int last_zoomed = (int)((((visible_hi_point - total_ios_graph_low_point)/total_ios_graph_range) * my_x)+.99);
System.out.print("last zoomed point: " + last_zoomed + "\n");

Is there a way to get the explicit location of the domainAxis for a given data point? Your response regarding iterating through the data implies it.

Bill Zahavi

Re: Getting the zoom range

Post by Bill Zahavi » Thu Jan 02, 2003 3:09 pm

"...The data in your dataset is not altered in any way. To find out how many points are displayed on the chart, you would have to iterate through all the data items and check whether or not they fall within the current axis ranges.

What gives the location of a data item on the axis?

Locked