Code: Select all
someChartPanel.addChartMouseListener(new ChartMouseListener() {
private int lineLoc = 0;
private XYLineAnnotation line = null;
@Override
public void chartMouseClicked(ChartMouseEvent e) {}
@Override
public void chartMouseMoved(ChartMouseEvent e) {
lineLoc = e.getTrigger().getX();
if (line != null) someChartPanel.getChart().getXYPlot().removeAnnotation(line);
line = new XYLineAnnotation(lineLoc, 0, lineLoc, 1000, new BasicStroke(1.5f), Color.RED);
someChartPanel.getChart().getXYPlot().addAnnotation(line);
System.out.println(lineLoc); // This works!!!
}
});