CrossHair Tracing In JFreeChart

浪尽此生 提交于 2019-12-12 09:24:35

问题


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/gui/ChartJDialog.java?revision=1.9&view=markup

However, I unable to obtained the correct y screen coordinate, when an subplot being added.

(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++

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);

回答1:


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();


来源:https://stackoverflow.com/questions/2204383/crosshair-tracing-in-jfreechart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!