单击按钮上的“放大"和“缩小"功能是否单击JfreeChart折线图? [英] Zoom In and Zoom out functionality on a button click on JfreeChart line graph?

查看:54
本文介绍了单击按钮上的“放大"和“缩小"功能是否单击JfreeChart折线图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我希望线图在按钮上单击时沿任意轴放大和缩小(总共4个按钮,X轴共2个按钮(X轴放大和缩小),Y轴另两个按钮)在负x轴和负Y轴区域上绘制的图形,取决于数据点,然后在单击按钮时,应根据按钮单击沿着该负x轴或负Y轴放大和缩小该图形.

我该如何实现?任何带有详细说明的示例代码都非常有帮助!

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

解决方案

每个按钮的 ChartPanel 来创建缩放命令的弹出菜单. actionPerformed() 是有关可用缩放功能的便捷指南.例如,通过调用zoomInDomain()处理ZOOM_IN_DOMAIN_COMMAND.根据此示例,相对于原点的典型 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;
}

如果默认zoomPoint就足够了,则可以使用图表面板的实现:

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

相反,原始示例中的createZoom()方法显示了如何调用ChartPanel方法,这将恢复两个轴上的自动范围计算.

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.

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. The implementation of actionPerformed() is a convenient guide to the available zooming functionality. For example, the ZOOM_IN_DOMAIN_COMMAND is handled by invoking zoomInDomain(). Based on this example, a typical Zoom X handler relative to the origin is shown below:

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:

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.

这篇关于单击按钮上的“放大"和“缩小"功能是否单击JfreeChart折线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆