tags:

views:

111

answers:

1

I've been using Incanter for my graphing needs, which was adequate but slow for my previous needs.

Now I need to embed a graph in a JPanel. Users will need to interact with the graph (e.g. clicking on certain points which the program would need to receive and deal with) by dragging and clicking. Zooming in a out is a must as well.

I've heard about JFreeChart on other SO discussions, but I see that Incanter uses that as its graphing engine, and it seemed somewhat slow then. It it actually fast, but perhaps Incanter is doing things that slow it down?

I'm graphing up to 2 million points (simple xy-plots, really), though generally will be graphing less. Using Matlab, this is plotted in a few seconds, but Incanter can hang for minutes.

So is JFreeChart the way to go? Or something else, given my needs?

Thanks so much!

(Also, it needs to be free, as it is for research.)

+3  A: 

Unfortunately, general purpose graphing solutions probably aren't going to scale well to 2 million points - that's big enough that you will need something specialized if you want interactive performance.

I can see a few sensible options:

  • Write your own custom "plotter" function that is optimized for drawing large numbers of points. You'd have to test it, but I think you might just about get the performance you want by writing the points directly to a BufferedImage using setRGB in a tight loop. If that still isn't fast enough, you can write the points directly into a byte array and construct a MemoryImageSource.

  • Exclude points so that you are only drawing e.g. 10,000 points maximum. This may be perfectly acceptable as long as you only really care about the overall shape of the scatter plot rather than individual points.

  • Pre-render all the points into e.g. a large BufferedImage then allow users to zoom in and out / interact with this static image. You might be able to "hack" JFreeChart to do this.

  • If OpenGL is an option (will require native code + getting up a steep learning curve!), then drop all the points in a big vertex array and get the graphics card to do it all for you. Will handle 2 million points in real-time without any difficulty.

mikera
Thank you for the advice: I might look into using OpenGL or only drawing as many points as are needed at a certain time. However, MatLab seems to handle around 1-2 million points quite nicely–and this is on an old, crappy Dell.
Isaac Hodes
You can reduce the number of points arbitrarily while keeping the overall shape using the Douglas-Peucker algorithm: http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
sanityinc
@Isaac - I expect that MatLab internally uses something like one of the approaches I mentioned.
mikera
I'm going with (well, trying to…) rolling my own OpenGL alternative. Also, point 2 will be used with my overview graph! Cheers, and thanks.
Isaac Hodes
@Isacc- no problem and good luck! If you haven't found them already its well worth looking at the NEHE Java ports for Java OpenGL examples .... http://pepijn.fab4.be/software/nehe-java-ports/
mikera