JFreeChart交互式图表编辑处理ChartMouseEvent [英] JFreeChart interactive chart editing handling ChartMouseEvent
问题描述
我正在尝试拦截ChartMouseEvent以修改使用ChartFactory.createXYLineChart方法创建的JFreeChart对象的XYSeries(并使用JDialog显示)。
I'm trying to intercept ChartMouseEvent in order to modify an XYSeries of a JFreeChart object created with ChartFactory.createXYLineChart method (and displayed using a JDialog).
< img src =https://i.stack.imgur.com/xG5s1.pngalt =XYLineChart>
我成功检索鼠标事件的坐标这样:
I retrieve successfully the coordinate of the mouse event this way:
public void chartMouseMoved(ChartMouseEvent arg0) {
int x = arg0.getTrigger().getX();
int y = arg0.getTrigger().getY();
坐标系(0,0)的原点位于图片中的红色方块。
现在,我想计算鼠标在哪个区间。为了做到这一点,我需要:
The origin of the coordinate system (0,0) is located at the red square in the picture. Now, I would like to calculate in which interval is the mouse in. In order to do this I need:
- 灰色图表的左上角坐标(绿色方块)
- 灰色图表的高度和宽度
我怎样才能得到这个值?
How can I get this values?
注意:我是JFreeChart的新手。如果我做错了,并且有更好的方法来实现这些目标,请让我朝着正确的方向前进。
A note: I'm a JFreeChart newbie. If I'm doing this wrong, and there is a better way to do achive these goals, please put me in the right direction.
推荐答案
您是通过 ChartPanel
渲染地图吗?
如果是,请查看 ChartPanel.getChartRenderingInfo()。getPlotInfo()。getDataArea()
。这应该返回一个易于使用的 Rectangle2D
。
If so, take a look at ChartPanel.getChartRenderingInfo().getPlotInfo().getDataArea()
. This should return a Rectangle2D
that is easy to work with.
这篇关于JFreeChart交互式图表编辑处理ChartMouseEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!