JFreeChart interactive chart editing handling ChartMouseEvent

感情迁移 提交于 2019-12-10 10:36:18

问题


I'm trying to intercept ChartMouseEvent in order to modify an XYSeries of a JFreeChart object created with ChartFactory.createXYLineChart method (and displayed using a JDialog).

I retrieve successfully the coordinate of the mouse event this way:

public void chartMouseMoved(ChartMouseEvent arg0) {
    int x = arg0.getTrigger().getX();
        int y = arg0.getTrigger().getY();

The origin of the coordinate system (0,0) is located at the red square in the picture. Now, I would like to calculate in which interval is the mouse in. In order to do this I need:

  1. the top-left coordinate of the grey chart (green square)
  2. height and width of the grey chart

How can I get this values?

A note: I'm a JFreeChart newbie. If I'm doing this wrong, and there is a better way to do achive these goals, please put me in the right direction.


回答1:


Are you rendering the plot via ChartPanel?

If so, take a look at ChartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(). This should return a Rectangle2D that is easy to work with.



来源:https://stackoverflow.com/questions/7189445/jfreechart-interactive-chart-editing-handling-chartmouseevent

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