使用 JFreeChart 动态构建和更新直方图
我有一个传入数据流,我想使用简单的直方图来绘制它们。我不知道值的范围,也不知道用于直方图的正确分辨率或箱宽。
SimpleHistogramDataset 提供了其中一些功能,但如果新值未被覆盖,我不想为了添加新的垃圾箱而处理捕获异常。此外,它不容易让我使用不同的箱宽度(可能是某些初始设置宽度的整数倍)重建直方图。
有没有一种简单的方法可以使用 JFreeChart 或其他图表库来完成此任务,或者我是否必须在这里编写自己的类?
I've got a stream of incoming data that I would like to plot using a simple histogram. I don't know the range of values, or the proper resolution or bin width to use for the histogram.
SimpleHistogramDataset provides some of this functionality, but I don't want to have to deal with catching exceptions in order to add new bins if the new value isn't covered. In addition, it doesn't easily allow me to rebuild the histogram using a different bin width (perhaps an integer multiples of some initial set width).
Is there an easy way to accomplish this with JFreeChart or some alternate charting library, or am I going to have to write my own class here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,你有一个经典的 MVC 场景。您的图表就是视图,您的控制器将根据您的模型协调重建此视图。
因此,您应该构建模型来反映传入的数据,控制器将根据此重新生成图表。因此,控制器可以确定是修改现有图表,还是根据新需求完全重建。图表实现(视图)不适合保存动态变化的数据结构本身。
It sounds to me like you have a classic MVC scenario. Your chart is the view, and your controller will coordinate rebuilding this view based upon your model.
So you should build your model to reflect the data coming in, and the controller will regenerate the chart based upon this. Consequently the controller can determine whether to modify an existing chart, or rebuild it completely based upon new requirements. The chart implementation (the view) isn't suited to holding the dynamically changing data structures itself.
在调用
addObservation()< 之前/code>
,您必须验证该值是否适合某个容器;使用
addBin()
相应地。重新绘制图表时,箱将自动调整大小以填充绘图区域。如果这不是所需的行为,则相应的 XYBarRenderer 可以扩展。如果必须删除垃圾箱,则必须使用removeAllBins()
。这使得 Brian Agnew 的 MVC 建议更加有说服力。作为参考,此示例展示了动态添加 XY 系列的效果。它可以让您了解更新是如何发生的。
Before you invoke
addObservation()
, you must verify that the value will fit in some bin; useaddBin()
accordingly. When the chart is redrawn, the bins will automatically resize to fill the plot area. If this is not the desired behavior, the corresponding XYBarRenderer can be extended. If you have to remove bins, you must useremoveAllBins()
. This makes Brian Agnew's MVC suggestion even more cogent.For reference, this example shows the effect of adding an XY series dynamically. It may give you a sense of how updates occur.