【问题标题】:JFreeChart restore zoom position after refreshJFreeChart 刷新后恢复缩放位置
【发布时间】:2016-05-03 19:47:27
【问题描述】:

我有以下方法

      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 
////////////


        }

问题是当我的数据被刷新时,我失去了缩放定位。

因此,我尝试在方法开始时获取 chartPanel 边界,然后尝试在方法结束时应用它 - 但是缩放定位只是不断恢复到默认位置,即整个图形.请问有人可以帮忙吗?

【问题讨论】:

  • 不清楚哪里出了问题;请编辑您的问题以包含一个minimal reproducible example,以显示您当前的方法。
  • @trashgod 我更新了我的问题
  • @trashgod 我正在浏览ing.iac.es/~docs/external/java/jfreechart/org/jfree/chart/… 上的指南,但无法让 getScaledDataArea() 工作!
  • 我无法使用here 所示的方法重现该问题,该方法更新了模型但保留了视图。
  • 是的,我尝试了很多不同的方法,我设法让缩放工作,但随后它在图表的中心随机缩放,而不是我在开始时得到的位置......你呢觉得有可能吗?

标签: java refresh zooming jfreechart


【解决方案1】:

我解决了这个问题:

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
        }
    }
}

【讨论】:

    猜你喜欢
    • 2011-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-08
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    相关资源
    最近更新 更多