I'm using JFreeChart to draw XYPlot. What I'm currently trying to do:
User clicks on the plot and the app gives him back the coordinates of the chosen point; I think that I've got it right. Here is some code:
public void chartMouseClicked(ChartMouseEvent arg0) { Rectangle2D plotArea = chPanel.getScreenDataArea(); XYPlot plot = (XYPlot) chart.getPlot(); double chartX = plot.getDomainAxis().java2DToValue(arg0.getTrigger().getPoint().getX(), plotArea, plot.getDomainAxisEdge()); double chartY = plot.getRangeAxis().java2DToValue(arg0.getTrigger().getPoint().getY(), plotArea, plot.getRangeAxisEdge()); JOptionPane.showMessageDialog(null, " x: "+chartX+ " y: "+chartY);}
I need to determine if user clicked on the line or not. The target is to mark the clicked spot if it is on the drawn graph.
I would be grateful for any clue.