views:

4834

answers:

9

There was an earlier thread on Java graph or chart library, where JFreeChart was found to be quite good, but, as stated in its FAQ, it's not meant for real-time rendering.

Can anyone recommend a comparable library that supports real-time rendering? Just some basic xy-rendering - for instance, getting a voltage signal from data acquisition system and plotting it as it comes (time on x-axis, voltage on y-axis).

+2  A: 

have a look at processing -- it's an open-source, java-based environment designed for all sorts of animated visualizations.

netzwerg
Are you sure its not itself a programming language, which perhaps influenced by Java? http://en.wikipedia.org/wiki/Processing_(programming_language)
Adeel Ansari
netzwerg
this tutorial (http://www.processing.org/learning/tutorials/eclipse) explains how to integrate the processing libraries into an existing java project -- it's focused on eclipse, but conceptually this will work with any other java IDE...
netzwerg
The conciseness of syntax looks somewhat similar to Groovy. Thanks for clarification.
Adeel Ansari
+4  A: 

What the FAQ actually says is that JFreeChart doesn't support hard real-time charting, meaning that the chart isn't updated when new data arrives or at deterministic interval after it. However I have found that JFreeChart can be used for the kind of applications you are describing. You can achieve 1 update per second, which is fine. I don't think a human eye can follow something quicker than this.

If you want something more than this, I doubt you will find anything in Java (or even in another language). Operating Systems that we use aren't designed to be real time. You can't have a guaranty that they will respond in a minimum interval after an event. A tight integration with the hardware driver will be needed to show more than 1-10 frames per second.

However, if you design your application correctly, the OS will do respond quickly and your application can easily display a "real-time" graph (meaning a graph that updates once a second). Just don't use your application to shut down a valve in an emergency situation!

kgiannakakis
Well, we're on a kind of boundary here. 1/s is certainly jerky for the eye if the data is changing much faster. 10/s would be fine, but JFreeChart can't probably do it.
Joonas Pulakka
Well if you calculate the data, then you could do 10 f/s in Java. I believe however that there is no way to do that if the data come from a data acquisition device. In that case you would need to communicate with the driver directly; this would be a much more difficult problem to solve.
kgiannakakis
+1 I've used JFreeChart for a real-time graph of stock prices.
Michael Myers
@kgiannakakis: ?! do you mean 10f/s as in 10 complete frames, or 10 incremental updates per second? I'm looking for a strip chart recorder, 1 updates/second is way too slow. Besides, there are a lot of data acquisition hardware modules that are pretty speedy, 10Ksamples/second is nothing. (whether any of them will work with Java is another story.... :( argh)
Jason S
I mean 10 updates per second. Each update will cover more than one frame. You'll never know if it is tolerable until you do some real tests.
kgiannakakis
+1  A: 

You could dig around the source for NetBeans. The profiler does real time graphing of various things such as memory usage.

TofuBeer
+3  A: 

http://www.live-graph.org/

Jacek Ławrynowicz
+2  A: 

Well, if it has to be Java, then you might want to look into these.

Adeel Ansari
+1  A: 

Fast enough for real time is swtchart, at least in my experience. Even with lots of data. Don't be scared away by the version number, yes it is a rather new API, but I use it successfully without problems.

As the name implies, it is based on SWT, which uses native OS drawing. Also it does some clever optimizations for drawing fast, like not drawing all points in the dataset (see Large Series Example Snippet).

the.duckman
+2  A: 

You probably have already found a good solution, but if not, I have recently done some work on a framework for producing 2D charts allowing for live updates at a rate of over 50 changes per second.

The original intention was to mimic the appearance of a chart recorder in a scrolling region of a web page, but I believe the approach has wider application.

A demo can be found at Chart Recorder Demo if anyone is interested.

The appearance is defined by a template (www.journeylog.co.uk/chart/templates/chartRecorder.xml). One feature is the ability to specify drawing either on the server or in the browser using ExplorerCanvas.

If anyone is interested I could start an open source project for it.

Alasdair Scott
Yes, I found that JFreeChart wass "real time enough" in my case. Anyway, your demo looks quite impressive! Open sourcing it would definitely be appreciated :-)
Joonas Pulakka
Very nice. I'm looking for a Java graph for Android and your solution may be adaptable... Hmmmm
Brad Hein
+2  A: 

Joonas, Sorry I haven't got sufficient reputation to reply to your comment.

I did some initial research, but started this framework when it looked as if my search for something suitable was taking longer than developing from scratch. Probably if I had been aware of your question and the answers, I wouldn't have done it!

However, judging from the server logs today it seems to have generated a certain amount of interest, so here are some more details of the technique:

  1. Like Google maps, it is tile based and only relies on JavaScript in the browser;

  2. Multiple instances are supported - for example the demo has two separate 'divs' for the scrolling and fixed regions. The XML configuration can be shared between them;

  3. It is designed for very large data sets, so for each curve, a user callback supplies the data for the tile window in suitable world coordinates;

  4. The XML configuration allows you to specify whether drawing takes place on the server or the client;

  5. The server maintains a set of visible tiles, and polls the same host application callback for extensions to the data series returned from the initial exposure. These are then passed to the browser with JSON and overlaid onto the image. The poll rate is configurable on a per curve basis, but I have tested it at close to a typical monitor refresh rate and it seems to perform reasonably well. Live data will actually give better performance than the current demonstration which is just presenting a repeating cycle of data;

  6. The work was done as part of a customer contract. I am currently in negotiations about making it available as open source. Any positive feedback here will I am sure have a positive influence!

mayfly
A: 

Alasdair Scott, an open source version would definitely be appreciated