2010-02-05 65 views
1

我能够实现实时鼠标跟踪如下:十字跟踪问题的JFreeChart的

alt text http://sites.google.com/site/yanchengcheok/Home/ok.png

的源代码如下:

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

但是,我无法获得正确的y屏幕坐标,当一个子图是adde d。

alt text http://sites.google.com/site/yanchengcheok/Home/notok.png

我怀疑我没有得到正确的屏幕数据区。

当在屏幕上只有一个情节,我得到高度的屏幕数据区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); 

回答

0

这是在深入JFreeChart源代码之后获得正确矩形的代码片段。

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