开发者

JFreeChart interactive chart editing handling ChartMouseEvent

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

JFreeChart interactive chart editing handling ChartMouseEvent

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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜