Get coordinates of cursor in JChart2D

那年仲夏 提交于 2019-12-12 03:20:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!