JFreeChart get mouse coordinates

后端 未结 1 1068
北荒
北荒 2020-12-29 13:10

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 tha

相关标签:
1条回答
  • 2020-12-29 13:41

    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());
    
    0 讨论(0)
提交回复
热议问题