简体   繁体   English

JFreeChart获取鼠标坐标

[英]JFreeChart get mouse coordinates

Is there a way in JFreeChart to determine from a ChartMouseEvent that x,y coordinates (in plot space) the mouse is over? 在JFreeChart中有没有办法从ChartMouseEvent确定鼠标结束的x,y坐标(在绘图空间中)? I've tried using the domain crosshair value but that seems inaccurate and lags the actual mouse event. 我尝试使用域十字准线值,但这看起来不准确,并且滞后于实际的鼠标事件。

thanks, 谢谢,

Jeff 杰夫

Mouse coordinates from getTrigger() are relative to ChartPanel so you need to convert them: getTrigger()鼠标坐标是相对于ChartPanel的,所以你需要转换它们:

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

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

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