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
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
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());
ChartPanel
has been scaled from its default dimensions. Removing the translateScreenToJava2D
step and supplying the point from MouseEvent.getPoint()
directly to java2DToValue
gives correct values in that case too. –
Sacrum © 2022 - 2024 — McMap. All rights reserved.