1

I have the following method

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


    //1. get chartPanel Bounds 
        Rectangle2D xy  = chartPanel.getScreenDataArea();

            Rectangle bounds = chartPanel.getBounds();
            int horz = (int) bounds.getX();//need to get the correct x and y
            int vertz = (int) bounds.getY();
            int width1 = (int) bounds.getWidth();
            int height1 = (int) bounds.getHeight();
            System.out.println(horz + " " + vertz + " " + width1 + " " +height1);//get positioning 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();

    //2.the problem lies here as i would expect the chartPanel.setBounds to restore the position that i got at 1.

        chartPanel.setBounds(horz,vertz,width1,height1);//xywidthheight
            System.out.println(chartPanel.getBounds());//set the positioning items as per the start 
////////////


        }

The issue is that when my data is refreshed i lose the zoom positioning.

I have therefore tried to get the chartPanel bounds at the start of the method and then try to apply it at the end of the method - however the zoom positioning just keeps on reverting back to the default position which is just the whole graph. Please can someone help?

Ingram
  • 654
  • 2
  • 7
  • 29
  • It's not clear where things go awry; please edit your question to include a [mcve] that shows your current approach. – trashgod May 04 '16 at 05:34
  • @ trashgod i have updated my question – Ingram May 04 '16 at 19:26
  • @ trashgod i was browsing the guides on http://www.ing.iac.es/~docs/external/java/jfreechart/org/jfree/chart/ChartPanel.html but cant get getScaledDataArea() to work! – Ingram May 04 '16 at 19:51
  • I can't reproduce the problem using the approach shown [here](http://stackoverflow.com/a/37020264/230513) that updates the model but leaves the view alone. – trashgod May 04 '16 at 20:00
  • yes i have tried so many different things i have managed to get a zoom working but then it zooms randomly on the center of the chart, rather than the position i get at the beginning ...do you think its possible? – Ingram May 04 '16 at 20:10
  • @trashgod i wish getScaledDataArea() to work – Ingram May 04 '16 at 20:28
  • I'm not familiar with that method. – trashgod May 04 '16 at 20:31
  • well its one that doesnt exist but exists in the guide check my second comment with the link.. – Ingram May 04 '16 at 20:35
  • It looks like an old or custom version. – trashgod May 04 '16 at 20:41
  • I dont really want to install an older version of JFC. Im going to experiment tonight, i think i may have to get the viewing rectangle somehow and translate a 2d point .. – Ingram May 04 '16 at 20:47
  • getscreendata is available on version 1.0.9 – Ingram May 04 '16 at 21:06
  • getscreendata is not any good. Do you know an alternative to JFC? – Ingram May 04 '16 at 21:25
  • I don't see it [here](https://sourceforge.net/p/jfreechart/code/HEAD/tree/trunk/source/org/jfree/chart/ChartPanel.java). – trashgod May 04 '16 at 22:30
  • Search with find it is there...public Rectangle2D getScreenDataArea() – Ingram May 04 '16 at 23:04
  • I thought you were looking for [`getScaledDataArea()`](http://www.ing.iac.es/~docs/external/java/jfreechart/org/jfree/chart/ChartPanel.html)? – trashgod May 05 '16 at 00:45
  • I have downloaded 1.0.9 and i get access to getScaledDataArea()? – Ingram May 05 '16 at 20:14
  • @ trashgod i worked the answer out and have answered my own question – Ingram May 08 '16 at 19:14

1 Answers1

0

I worked this out:

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
        }
    }
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Ingram
  • 654
  • 2
  • 7
  • 29