I would like to catch click event over JFreeChart and show by console the x and y value of the nearest data, not just clicks within the boundary of a ChartEntity
.
If it is not possible (y value is not exist for that x value), I would like to get the x value.
EDIT:
Marker shows so far to click. Click handler code:
Point2D po = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
Rectangle2D plotArea = chartPanel.getScreenDataArea();
XYPlot plot = (XYPlot) chart.getPlot();
chartX = plot.getDomainAxis().java2DToValue(po.getX(), plotArea, plot.getDomainAxisEdge());
chartY = plot.getRangeAxis().java2DToValue(po.getY(), plotArea, plot.getRangeAxisEdge());
plot.removeDomainMarker(marker);
marker = new ValueMarker(chartX);
marker.setPaint(Color.red);
plot.addDomainMarker(marker);
System.out.println("X:" + chartX + ", Y:" + chartY);