开发者

JFreeChart in scrollpane

开发者 https://www.devze.com 2022-12-11 03:51 出处:网络
I\'m having a big graph created with jf开发者_运维问答reechart. 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 i

I'm having a big graph created with jf开发者_运维问答reechart. 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


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.


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);


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".


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号