Jfreechart - 根据变化的数据刷新图表
我想知道如果我们想“实时”更改某些数据,如何刷新图表。我的意思是,例如,我有一个包含 3 年任务系列的图表,我想将 3 年更改为 5 年。我希望图表立即改变。
有某种更新图表或类似的东西吗?
我知道您可能会说“获取您的任务系列,进行更改,它将自动刷新”,但我的任务系列已生成,我无法轻松更改这些任务系列。这就是为什么我想找到一种方法来重新计算并重建整个图表。
I would like to know how to refresh a chart if we want to change "in live" some piece of data. I mean for instance, I have a chart with a TaskSeries which appears on 3 years and I would like to change 3 years by 5 years. I want the chart to change immediately.
Is there some kind of update chart or something like that ?
I know that you could say "get your TaskSeries, do your changes and it will be refreshed automatically" but my TaskSeries are generated and I cannot easily change these ones. That's why I would like to find a way to recalculate and to rebuild the whole chart.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
TaskSeries
自动发送SeriesChangeEvent
到所有已注册的侦听器,例如CategoryPlot
。在此示例中,DynamicTimeSeriesCollection
实现 <代码>SeriesChangeEvent。在本例中,图表的XYPlot
是已注册的侦听器。The
add()
method ofTaskSeries
automatically sends aSeriesChangeEvent
to all registered listeners, e.g.CategoryPlot
. In this example,DynamicTimeSeriesCollection
implementsSeriesChangeEvent
. In this case, the chart'sXYPlot
is a registered listener.我在使用 XYPlot 时也遇到了这个问题。我通过重置数据集找到了解决方法:
这很疯狂,但它有效...
注意:
chart.setNotify(true)
似乎什么也没做。I had this issue too with an XYPlot. I found a workaround by resetting the dataset:
that's crazy but it works...
Note:
chart.setNotify(true)
seems to do nothing.我有这个问题;我用这个做到了:
I had this issue; I did it using this:
对我有用的是以下内容:
What worked with me was the following:
我还没有找到一种简单的方法来“实时”更新 JFreeChart,因为 jfreechart 的数据结构与我的数据结构非常不兼容。因此,我构建了自己的 redraw() 方法,该方法从我的 dataModel 收集数据,构建 JFreeChart dataModel 并设置新的图表。
这给人一种“实时”更新的感觉,而且非常难看。
I haven't found an easy way to update a JFreeChart "live", since the data-structure of jfreechart is very incompatible to my data-structure. So I build a redraw()-Method of my own, that collects the data from my dataModel, build up a JFreeChart dataModel and set the chart new.
This gives the feeling of a "live" update, also it is very ugly.