JFreeChart中的跨头发跟踪 [英] CrossHair Tracing In JFreeChart
问题描述
我能够实现如下实时鼠标跟踪:
I was able to implement real-time mouse tracing as follow :
源代码如下:
但是,添加子图时,我无法获得正确的y屏幕坐标.
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.
当屏幕上只有一个图时,我得到一个高度为300 ++的屏幕数据区域
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);
推荐答案
以下是在深入研究JFreeChart源代码后获得正确矩形的代码段.
Here is the code snippet to obtained the correct rectangle after dive into JFreeChart source code.
/* Try to get correct main chart area. */
final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(0).getDataArea();
这篇关于JFreeChart中的跨头发跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!