我能够实现实时鼠标跟踪如下:
源代码如下:
但是,当添加子图时,我无法获得正确的 y 屏幕坐标。
我怀疑我没有得到正确的屏幕数据区域。
当屏幕中只有一个绘图时,我得到一个高度为 300++ 的屏幕数据区域
当一个子图添加到底部时,由于新添加的子图占用的高度,我预计屏幕数据区域的高度会降低。
但是,我不知道如何为第一个绘图获取正确的屏幕数据区域。
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);