本文介绍了Jfree图表鼠标拖动以缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修改ChartPanel的mouseDragged事件,以便在缩放之前/之后要进行一些处理?我有以下chartPanel,

How to modify mouseDragged event of ChartPanel such that I want to do some processing before/after the zooming is done? I have the following chartPanel,

JFreeChart chart = new JFreeChart(
                "Demo", JFreeChart.DEFAULT_TITLE_FONT,plot, true);
ChartPanel chartPanel = new ChartPanel(chart);

无论何时拖动鼠标,我都想在调用mouseDragged()之前/之后调用我的函数.这该怎么做 ?

Whenever the mouse is dragged, I want to call my function before/ after the mouseDragged() is called. How to do this ?

chartPanel.addMouseMotionListener(new MouseMotionListener() {

    @Override
    public void mouseDragged(MouseEvent e) {
        // TODO Auto-generated method stub
    }

我看不到super.mouseDragged(e).图表放大后如何调用我的函数.基本上,我想做的是在图表放大后,我要获取x和y坐标的范围并添加合适的XYAnnotation.我该怎么办?

i am unable to see super.mouseDragged(e).how to invoke my function after the chart is zoomed. Basically what i want to do is after the chart is zoomed, I want to get the range of x and y coordinates and add a suitable XYAnnotation. How can I do this ?

推荐答案

您可以覆盖并在super.mouseDragged(e)之前或之后进行处理.

You can override mouseDragged() in org.jfree.chart.ChartPanel and do your processing before or after super.mouseDragged(e).

附录: MouseMotionAdapter 可能是一个方便的替代方法:

Addendum: MouseMotionAdapter may be a convenient alternative:

chartPanel.addMouseMotionListener(new MouseMotionAdapter() {

    @Override
    public void mouseDragged(MouseEvent e) {
        // process before
        super.mouseDragged(e);
        // process after
    }
});

这篇关于Jfree图表鼠标拖动以缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 09:02