如何制作可定制的图表
我希望使用 java2d API 制作一个图表,用户可以在其中使用鼠标操作某些功能 - 例如用于轴的比例或围绕图表上绘制的不同点移动。
到目前为止,我发现的只是 Graphics2D 对象上的 drawX 方法,但是似乎没有一种简单的方法来捕获用户单击其中一个方法并移动它以便我可以重新绘制图形。
谁能建议最好/最简单的方法来实现这个?只是寻找正确方向的一个点。
I'm looking to use the java2d API to make a graph in which users can manipulate certain features using their mouse - such as the scale used for an axis or move around the different points plotted on the graph.
So far all I have found is the drawX methods on a Graphics2D object, however there does not seem to be an easy way to capture a user clicking on one of these and moving it so that I can redraw the graph.
Can anyone suggest the best/easiest way to implement this? Just looking for a point in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不重新发明轮子始终是最好的方法,有很多优秀的库可以使用:http://www.jfreechart.org/jfreechart/。 jfree.org/jfreechart/
如果您想自己实现这一点,您将在实际用于显示图表的任何组件(例如 JPanel)上监听鼠标事件,然后必须在屏幕和图表坐标以确定您需要更改的内容。
Not reinventing the wheel is always the best way, there are plenty of excellent libraries you can use: http://www.jfree.org/jfreechart/
If you are looking to implement this yourself, you would listen to mouse events on whatever component you're actually using to display your chart (say a JPanel), and then would have to convert between screen and chart coordinates to figure out what you need to change.