English 中文(简体)
JFreeChart in scrollpane
原标题:

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

问题回答

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签