Experimenting with GLJPanel and jfreechart

05 Jan 2010
Posted by colby

credit: JFree.org

In the interest of having snappy plotting software for use on the ATA software, I'm experimenting with jfreechart and how it updates a dynamic plot, and jfreechart's admitted performance issue:

From section 10.2.2 of the jfreechart 1.0.13 Developer Guide:

10.2.2 Performance
Regarding performance, you need to be aware that JFreeChart wasn’t designed specifically for generating real-time charts. Each time a dataset is updated, the ChartPanel reacts by redrawing the entire chart. Optimisations, such as only drawing the most recently added data point, are
difficult to implement in the general case, even more so given the Graphics2D abstraction (in the Java2D API) employed by JFreeChart. This limits the number of “frames per second” you will be able to achieve with JFreeChart. Whether this will be an issue for you depends on your data, the requirements of your application, and your operating environment.

I was wondering if the drawing was offloaded to opengl (and therefore more on the graphics card), that this updating process might be improved for this admittedly 2D focused work. I'm doing this on my core 2 duo mac pro, ~2007, which has 2 GeForce 7300's in it (not top of the line, but no slouch).

There are Java OpenGL bindings in the form of the JOGL library from Sun Microsystems. JOGL comes with a class called GLJPanel which extends swing.JPanel, making it a drop-in replacement.

By taking the freely available source code to jfreechart, I attempted to test if the OpenGL version would perform better than the generic JPanel. The dynamic/real-time demos I tested, come from the jfreechart source base and manual and they rely on the underlying jfreechart class, ChartPanel, which in turn, extends JPanel.

(note to self, contents of work are in Notebook/ATA/jfreechart/ )

Steps:

  1. checkout jfreechart,), svn co https://jfreechart.svn.sourceforge.net/svnroot/jfreechart jfreechart
    1. stable is 1.0.13 or jfreechart/branches/jfreechart-1.0.x-branch
  2. Download jogl-2.0-macosx-universal.zip from http://download.java.net/media/jogl/builds/archive/jsr-231-2.0-beta10/
    and unzipped it in jfreechart-1.0.x-branch. Ran profile.jogl script in jogl-2.0-macosx-universal/etc
    1. . jogl-2.0-macosx-universal/etc/profile.jogl JOGL_ALL /Users/colby/Notebook/ATA/jfreechart/jfreechart/branches/jfreechart-1.0.x-branch/jogl-2.0-macosx-universal/lib
  3. Edited jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java and substituted GLJPanel for JPanel
  4. Downloaded jcommon-1.0.16.jar and added to CLASSPATH to fulfill pre-req for jfreechart
  5. went into jfreechart-1.0.x-branch/ant and did a build (ant with no build target).
  6. Made sure CLASSPATH had new jfreechart jars in place.
  7. Downloaded DynamicDataDemo3.java and MemoryUsageDemo.java, built normally, ran against GLJPanel vs JPanel

Initial results seem disappointing, as noted in the following videos. My suspicion is that the graphics primitives being used by jfreechart are ending up being translated to GL. It would be interesting to add a layer to jfreechart that uses a GLDrawable (received from a passed in GLU context) as part of a jfree.plot.Plot interface (adding it as part of the draw(...) method) and then using that for the underlying primitives, will follow up.


GLJPanel, voice: me. (click here if you're unable to see the embedded video)


JPanel, voice: me. (click here if you're unable to see the embedded video)


Both GLJPanel and JPanel, voice: me. (click here if you're unable to see the embedded video)

AttachmentDateSize
[file] GLJPanelDynamic.mov05/01/10 1:05 am7.25 MB
[file] JPanelDynamic.mov05/01/10 1:05 am10.26 MB
[file] GLJPanelandJPanelMemoryUsage.mov05/01/10 1:05 am8.82 MB