简体   繁体   English

JFreeChart中的跨头发跟踪

[英]CrossHair Tracing In JFreeChart

I was able to implement real-time mouse tracing as follow : 我能够实现实时鼠标跟踪,如下所示:

替代文字

The source code is as follow : 源代码如下:

http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/charting/CrossHairUI.java?revision=1.5&view=markup http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/charting/CrossHairUI.java?revision=1.5&view=markup

http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/gui/ChartJDialog.java?revision=1.9&view=markup http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/gui/ChartJDialog.java?revision=1.9&view=markup

However, I unable to obtained the correct y screen coordinate, when an subplot being added. 但是,添加子图时,无法获得正确的y屏幕坐标。

(broken image) (残影)

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++ 当屏幕上只有一个图时,我得到一个高度为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);

Here is the code snippet to obtained the correct rectangle after dive into JFreeChart source code. 这是深入研究JFreeChart源代码后获得正确矩形的代码段。

/* Try to get correct main chart area. */
final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(0).getDataArea();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM