Retaining the zoom after data refresh

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Mr Assistance
Posts: 5
Joined: Thu May 05, 2016 10:06 pm
antibot: No, of course not.

Retaining the zoom after data refresh

Post by Mr Assistance » Thu May 05, 2016 10:14 pm

I really need some help - i have asked everyone i know but still cant get an answer to my problem.

I have a method whereby at the start of the method i try and get the zoom level, and then try to set the zoom level at the end of the method. However i cannot get the zoom level to set.

Here is my method

Code: Select all

private void passStingR(StringBuilder retVal) throws BadLocationException, Exception {
int getinitialscrollpos;
getinitialscrollpos = getinitialscrollPosition(scrollMEL);
Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();//obtain the zoom
   
////////////////refresh data////

Document docR = null;

docR = loadXMLFromString(retVal.toString());//pull in the XML data into a new doc
populate1R(docR);
tableMEL.getTableHeader().setReorderingAllowed(false);//prevent user from changing column order now at refresh level
SimpleDateFormat time_formatterR = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String current_time_strR = time_formatterR.format(System.currentTimeMillis());
updatetFieldDG.setText(current_time_strR);
middlePanel.add(scrollMEL);
scrollMEL.getVerticalScrollBar().setValue(getinitialscrollpos);
System.out.println("End" + getinitialscrollpos);
getTableData(tableMEL);
head(tableMEL);
createGraphGUI();

/////////////////////
  
    Rectangle2D r = plotArea;

chartPanel.zoom(r);

//restoreZoomPoint

    }
I require some help urgently as i have been stuck on this problem for over a week now.

My graph type is as follows defined by:

Code: Select all

	public void createGraphGUI()  {
	DefaultCategoryDataset dataset = createDataset();
	chart = createChart(dataset);
	
chartPanel.setMouseWheelEnabled(true);
chartPanel.setHorizontalAxisTrace(true);
chartPanel.setVerticalAxisTrace(true);

chartPanel.setChart(chart);
chartPanel.setVisible(true);
	}
Help much appreciated.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Retaining the zoom after data refresh

Post by paradoxoff » Fri May 06, 2016 12:24 pm

Mr Assistance wrote:

Code: Select all

private void passStingR(StringBuilder retVal) throws BadLocationException, Exception {
Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();//obtain the zoom
Rectangle2D r = plotArea;
chartPanel.zoom(r);
}
If the size of the ChartPanel has not changed before requesting and setting the area, the call to chartPanel.zoom(r) should give the same result as if a user had dragged a zoom reactangle across the entire data area. And using the entire data area as "zoom rectangle" won´t do any zooming!
If you need to capture axis ranges and restore them later on, you need to determine the type of the plot, iterate over all ValueAxes (for an XYPlot, this iteration needs to include domain and range axes, for a CategoryPlot, you only need the range axes), store their ranges in a suitable data structure (such as a HashMap<ValueAxis,Range>), then do whatever is done in you passStingR method, and finally restore the axis ranges by again iterating over the ValueAxes of the plot and give each the range that ih had before by retrieving that from the data structure.

Mr Assistance
Posts: 5
Joined: Thu May 05, 2016 10:06 pm
antibot: No, of course not.

Re: Retaining the zoom after data refresh

Post by Mr Assistance » Fri May 06, 2016 9:18 pm

violajsilver wrote:Try to contact some experts to solve this problem.
Useless answer I am on a board asking experts.

Mr Assistance
Posts: 5
Joined: Thu May 05, 2016 10:06 pm
antibot: No, of course not.

Re: Retaining the zoom after data refresh

Post by Mr Assistance » Fri May 06, 2016 9:18 pm

Mr Assistance wrote:
violajsilver wrote:Try to contact some experts to solve this problem.
Useless answer I am on a board asking experts.

Mr Assistance
Posts: 5
Joined: Thu May 05, 2016 10:06 pm
antibot: No, of course not.

Re: Retaining the zoom after data refresh

Post by Mr Assistance » Fri May 06, 2016 9:20 pm

paradoxoff wrote:
Mr Assistance wrote:

Code: Select all

private void passStingR(StringBuilder retVal) throws BadLocationException, Exception {
Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();//obtain the zoom
Rectangle2D r = plotArea;
chartPanel.zoom(r);
}
If the size of the ChartPanel has not changed before requesting and setting the area, the call to chartPanel.zoom(r) should give the same result as if a user had dragged a zoom reactangle across the entire data area. And using the entire data area as "zoom rectangle" won´t do any zooming!
If you need to capture axis ranges and restore them later on, you need to determine the type of the plot, iterate over all ValueAxes (for an XYPlot, this iteration needs to include domain and range axes, for a CategoryPlot, you only need the range axes), store their ranges in a suitable data structure (such as a HashMap<ValueAxis,Range>), then do whatever is done in you passStingR method, and finally restore the axis ranges by again iterating over the ValueAxes of the plot and give each the range that ih had before by retrieving that from the data structure.
Thanks for the info on the axis . i am going to experiment with the range axis retention

Mr Assistance
Posts: 5
Joined: Thu May 05, 2016 10:06 pm
antibot: No, of course not.

Re: Retaining the zoom after data refresh

Post by Mr Assistance » Sun May 08, 2016 8:15 pm

Here is the answer - may be useful for someone else

Code: Select all

private void passStingR(StringBuilder retVal) throws BadLocationException, Exception {
int getinitialscrollpos;
getinitialscrollpos = getinitialscrollPosition(scrollMEL);

try {
CategoryPlot plot = (CategoryPlot) chartPanel.getChart().getPlot();//get plot of graph
//System.out.print("Plot Type" + plot);
ValueAxis rangeAxis = plot.getRangeAxis();//get range of axis of graph

System.out.print("Range " + rangeAxis);//get range lower and upper as an array

map.put(1, rangeAxis);

} catch(Exception e) {
System.out.print("Error has occured");
} finally {
////////////////refresh data////

Document docR = null;

docR = loadXMLFromString(retVal.toString());//pull in the XML data into a new doc
populate1R(docR);
tableMEL.getTableHeader().setReorderingAllowed(false);//prevent user from changing column order now at refresh level
SimpleDateFormat time_formatterR = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String current_time_strR = time_formatterR.format(System.currentTimeMillis());
updatetFieldDG.setText(current_time_strR);
middlePanel.add(scrollMEL);
scrollMEL.getVerticalScrollBar().setValue(getinitialscrollpos);
System.out.println("End" + getinitialscrollpos);
getTableData(tableMEL);
head(tableMEL);
createGraphGUI();






if (map.get(1) != null) {
    System.out.print("get map" + map.get(1));
CategoryPlot plot = (CategoryPlot) chartPanel.getChart().getPlot();
plot.setRangeAxis(map.get(1));//get range of axis of graph
}



}




    }

Locked