滚动窗格中的 JFreeChart
我正在使用 jfreechart 创建一个大图表。该图表对于屏幕来说太大了,所以我想将其放在滚动窗格中。然而,当使用滚动条时,每次都会重新绘制完整的图形,这使得速度非常慢。有解决办法吗?
谢谢,
巴特
I'm having a big graph created with jfreechart. This chart is too big for the screen, so I would like to put it in a scrollpane. However, when using the scrollbar, the complete graph is redrawn everytime, which makes it extremely slow. Is there a solution for this?
thanks,
Bart
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
自己缓冲吧。在不位于可见面板上的面板中渲染 JFreeChart,并将其用作滚动窗格中的面板的缓冲区。然后您可以控制重绘事件以及同步两个面板的频率。
Buffer it yourself. Render the JFreeChart in a panel that is not on a visible panel and use that as your buffer to the panel that is in the scrollpane. Then you can control the repaint events and how often you sync the two panels.
浏览源代码 显示 ChartPanel 构造函数采用一个可选的布尔参数,该参数指示它在重新绘制时使用图像缓冲区。我想这会有帮助。
Glancing at the source reveals that the ChartPanel constructor takes an optional boolean parameter, which instructs it to use an image buffer when repainting. I'd guess that would help.
使用 JFreeChart,当从基础数据集触发事件时,将始终重新绘制完整的图表,无论图表是否嵌入到
JScrollPane
中。如果您的图表包含大量数据点并且经常更新,这一点尤其明显。您可以尝试一些“拼凑”来让您的 UI 更具响应性;例如,
SeriesDataset
),则如果当前未显示图表,您可以延迟触发SeriesChangeEvent
。SeriesChangeEvent
来限制多个更新,而不是在每个事件上触发,明显的缺点是您的 UI 不太“实时”。With JFreeChart, the complete chart will always be redrawn when an event is fired from the underlying dataset, irrespective of whether the chart is embedded within a
JScrollPane
or not.This is particularly noticeable if your chart contains a large number of datapoints and is updated frequently. There are some "kludges" you can attempt you make your UI more responsive; e.g.
SeriesDataset
) you could delay firing aSeriesChangeEvent
if the chart is not currently being displayed.SeriesChangeEvent
every N seconds rather than on every event, the obvious downside being that your UI is less "real-time".我实际上认为问题不是因为面板本身,而是因为其他地方触发的其他事件。我实际上确实在 jscrollpanes 中使用了 ChartPanel,但没有这种行为。我的应用程序运行顺利。
同意 Adamsky 的观点,我的建议是停止在图表渲染中查找问题,而在数据集实现中查找问题。
I actually think that the problem is not because of the panel itself, but of some other events fired somewhere else. I do actually use ChartPanel inside jscrollpanes without that behaviour. My application works smoothly.
Agreeing with Adamsky, my advice is to stop looking the problem in the chart rendering but in your dataset implementation.