JFreeChart获取鼠标坐标 [英] JFreeChart get mouse coordinates

查看:399
本文介绍了JFreeChart获取鼠标坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JFreeChart中是否有办法从ChartMouseEvent确定鼠标结束的x,y坐标(在绘图空间中)?我尝试使用域十字准线值,但这似乎不准确,并且滞后于实际的鼠标事件。

Is there a way in JFreeChart to determine from a ChartMouseEvent that x,y coordinates (in plot space) the mouse is over? I've tried using the domain crosshair value but that seems inaccurate and lags the actual mouse event.

谢谢,

Jeff

推荐答案

getTrigger()中的鼠标坐标是相对的ChartPanel所以你需要转换它们:

Mouse coordinates from getTrigger() are relative to ChartPanel so you need to convert them:

Point2D p = chartPanel.translateScreenToJava2D(mouseChartEvent.getTrigger().getPoint());
Rectangle2D plotArea = chartPanel.getScreenDataArea();
XYPlot plot = (XYPlot) chart.getPlot(); // your plot
double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());

这篇关于JFreeChart获取鼠标坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆