滚动窗格中的 JFreeChart

发布于 2024-08-11 02:12:41 字数 123 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

十秒萌定你 2024-08-18 02:12:41

自己缓冲吧。在不位于可见面板上的面板中渲染 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.

凉墨 2024-08-18 02:12:41

浏览源代码 显示 ChartPanel 构造函数采用一个可选的布尔参数,该参数指示它在重新绘制时使用图像缓冲区。我想这会有帮助。

public ChartPanel(JFreeChart chart, boolean useBuffer);

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.

public ChartPanel(JFreeChart chart, boolean useBuffer);
安静被遗忘 2024-08-18 02:12:41

使用 JFreeChart,当从基础数据集触发事件时,将始终重新绘制完整的图表,无论图表是否嵌入到 JScrollPane 中。

如果您的图表包含大量数据点并且经常更新,这一点尤其明显。您可以尝试一些“拼凑”来让您的 UI 更具响应性;例如,

  • 如果您的基础数据集已更新(例如SeriesDataset),则如果当前未显示图表,您可以延迟触发SeriesChangeEvent
  • 类似地,您可以通过每隔 N 秒定期触发 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.

  • If you underlying dataset is updated (e.g. SeriesDataset) you could delay firing a SeriesChangeEvent if the chart is not currently being displayed.
  • Similarly you could throttle multiple updates by only periodically firing SeriesChangeEvent every N seconds rather than on every event, the obvious downside being that your UI is less "real-time".
美羊羊 2024-08-18 02:12:41

我实际上认为问题不是因为面板本身,而是因为其他地方触发的其他事件。我实际上确实在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文