views:

592

answers:

1

Is there a way in JFreeChart to determine from a ChartMouseEvent that x,y coordinates (in plot space) the mouse is over? I've tried using the domain crosshair value but that seems inaccurate and lags the actual mouse event.

thanks,

Jeff

+3  A: 

Mouse coordinates from getTrigger() are relative to ChartPanel so you need to convert them:

Point2D p = chartPanel.translateScreenToJava2D(mouseChartEvent.getTrigger().getPoint());
Rectangle2D plotArea = chartPanel.getScreenDataArea();
XYPlot plot = (XYPlot) chart.getPlot(); // your plot
double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
ChssPly76
Thanks. I couldn't figure out what the plotArea argument was supposed to be. Worked like a charm, appreciate it.
Jeff Storey