Jfree chart Mouse Drag to Zoom

邮差的信 提交于 2019-12-11 03:57:31

问题


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. How can I do this ?


回答1:


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


来源:https://stackoverflow.com/questions/7089206/jfree-chart-mouse-drag-to-zoom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!