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

这篇博客讨论了如何在Java中创建一个图表,允许用户通过点击按钮来实现X轴和Y轴的缩放。每个按钮的实现都调用了与图表面板中用于创建缩放菜单的相应方法。例如,`ZoomX`按钮通过调用`zoomInDomain(0, 0)`来实现相对于原点的X轴缩放。如果需要使用图表面板的默认缩放点,可以直接使用`ChartPanel`的方法。博客提供了创建缩放按钮的示例代码,并指出了如何恢复自动边界的方法。
摘要由CSDN通过智能技术生成

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;

}

GSY7c.png

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.

Q4B6C.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值