开发者

Jfree chart Mouse Drag to Zoom

开发者 https://www.devze.com 2023-03-28 10:32 出处:网络
How to modify mouseDragged event of ChartPanel such that I want to do some processing before/after the zooming is done?

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);

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
    }

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. 开发者_StackOverflow社区How can I do this ?


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

Addendum: MouseMotionAdapter may be a convenient alternative:

chartPanel.addMouseMotionListener(new MouseMotionAdapter() {

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号