问题
I'm using JChart2D for trace a values of a double array. I'm using ZoomableChart and I want get coordinates (x, y) of cursor when this stay over ZoomableChart in my code to show them in a JLabel and draw a vertical line.
- How can I get the coordinates of the cursor?
- How can I draw this line?
回答1:
To get a point is easy. Add a MouseMotionListener to the ZoomableChart.
I'm guessing you want this information to represent a point in the data in the chart, rather than in the potentially zoomed ZoomableChart component itself. For that you'll need to look to something like (trawling through the docs for a class I heard of 'today'..) Chart2D.getPointFinder(), the finder apparently offers getNearestPoint(MouseEvent,Chart2D) to map a MouseEvent back to the underlying structure.
Go for it! :)
来源:https://stackoverflow.com/questions/9469775/get-coordinates-of-cursor-in-jchart2d