I was able to implement real-time mouse tracing as follow :
The source code is as follow :
However, I unable to obtained the correct y screen coordinate, when an subplot being added.
I suspect I didn't get the correct screen data area.
When there is only one plot in the screen, I get a screen data area with height 300++
When a sub plot added to the bottom, I expect screen data area height will be reduced, due to the height occupied by the newly added subplot.
However, I have no idea how to obtain the correct screen data area for the first plot.
final XYPlot plot = (XYPlot) cplot.getSubplots().get(0);
// Shall I get _plotArea represents screen for getSubplots().get(0)?
// How?
// I try
//
// chartPanel.getScreenDataArea(0, 0);
// chartPanel.getScreenDataArea(0, 1);
// chartPanel.getScreenDataArea(1, 0);
// chartPanel.getScreenDataArea(1, 1);
//
// All returned null
// OK. I suspect this is causing me unable to get the correct screen y coordinate
// I always get the same _plotArea, although a new sub plot had been added.
final Rectangle2D _plotArea = chartPanel.getScreenDataArea();
final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
final double yJava2D = rangeAxis.valueToJava2D(yValue, _plotArea, rangeAxisEdge);