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).
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:
开发者_运维百科- the top-left coordinate of the grey chart (green square)
- 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.
精彩评论