简体   繁体   English

单击按钮上的“放大”和“缩小”功能是否单击JfreeChart折线图?

[英]Zoom In and Zoom out functionality on a button click on JfreeChart line graph?

Basically i want the line graph to be zoomed in and Zoomed out(total 4 buttons,2 for X-axis(Zoom in and Zoom out) and other two for Y-axis) on a button click along any axis like if the graph drawn on negative x-axis and negative Y-axis area ,depending on data points then on button click the graph should be Zoomed in and Zoomed out along that negative x-axis or negative Y-axis based on button click. 基本上我希望按钮上的线图被放大和缩小(总共4个按钮,X轴共有2个按钮(X轴具有放大和缩小),Y轴另外两个按钮)可以沿任意轴单击,就像绘制图形一样在负x轴和负Y轴区域上,取决于数据点,然后在单击按钮时,应基于按钮单击沿着该负x轴或负Y轴放大和缩小图形。

How can i achieve this ?Any sample code with detail Explanation is much helpful!! 我该如何实现呢?任何带有详细说明的示例代码都非常有帮助!

 private JButton createZoom()
 {
        final JButton auto = new JButton("ZOOMIN");
        auto.setActionCommand("ZOOM_IN_DOMAIN");
        auto.addActionListener(new ChartPanel(chart));
        return auto;
    }

Each button's Action implementation should invoke the corresponding method used by ChartPanel to create it's popup menu of zoom commands. 每个按钮的Action实现应调用ChartPanel使用的相应方法来创建缩放命令的弹出菜单。 The implementation of actionPerformed() is a convenient guide to the available zooming functionality. actionPerformed()的实现是有关可用缩放功能的便捷指南。 For example, the ZOOM_IN_DOMAIN_COMMAND is handled by invoking zoomInDomain() . 例如, ZOOM_IN_DOMAIN_COMMAND通过调用处理zoomInDomain() Based on this example , a typical Zoom X handler relative to the origin is shown below: 基于此示例 ,相对于原点的典型Zoom X处理程序如下所示:

private JButton createZoom() {
    final JButton zoomX = new JButton(new AbstractAction("Zoom X") {

        @Override
        public void actionPerformed(ActionEvent e) {
            chartPanel.zoomInDomain(0, 0);
        }
    });
    return zoomX;
}

If the default zoomPoint is sufficient, you can use the chart panel's implementation: 如果默认的zoomPoint足够,则可以使用图表面板的实现:

private JButton createZoom() {
    final JButton zoomX = new JButton("Zoom X");
    zoomX.setActionCommand(ChartPanel.ZOOM_IN_DOMAIN_COMMAND);
    zoomX.addActionListener(chartPanel);
    return zoomX;
}

放大图像

In contrast, the createZoom() method in the original example shows how to evoke the ChartPanel method restoreAutoBounds() , which restores the auto-range calculation on both axes. 相反,原始示例中的createZoom()方法显示了如何调用ChartPanel方法restoreAutoBounds() ,该方法将恢复两个轴上的自动范围计算。

图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM