views:

878

answers:

1

I have a combined plot in JFreechart consisting of 4 timeseries charts with a common time domain axis.

The data for the subplots arrives at different rates. For example I may receive a price change event every couple of miliseconds and a position change every minute. I'm currently rendering these series with the XYStepRenderer to produce a step charts.

I'd like to be able to do something like this:

  • A Price point is received at time T and is plotted on chart
  • No data has been received at time T for the position chart and so we assume that the value has not changed and the previous position value is rendered - i.e. extending the step line horizontally
  • At time T+1 a position point is received and is plotted changing the step chart
  • At time T+1 no price point has been received and so the previous price is plotted

Is there any easy way to do this in JFreechart? Currently I have a working implementation but this does not handle rendering the assumed values.

My initial thoughts have been around changing the data model so that I can quickly find the previous value and to change the calls to tell each subplot to draw when an event is received for any plot.

+2  A: 

I think you'll need to buffer the incoming changes and apply a ruleset for forwarding changes onto JFreeChart (which is not really recommended for real-time work btw., but I've found that for low frequency updates it works well).

I'm guessing you have a dataset for the prices and a dataset for the positions. Do your position and price updates come in with a timestamp ? If not, you'll have the problem of receiving these sequentially and trying to tie them up (perhaps updates arriving within a certain timewindow map to the same time instant?). If they do have timestamps, then you can derive a new position (same as the old position) when the price comes in, and then replace that if need be.

I would decouple the chart updating from the position/price updates whatever happens, just in case you get swamped with position/price changes. You don't want that to translate into multiple chart updates that you're going to have to throw away immediately.

Brian Agnew
Thanks for your suggestion Brian. I am receiving timestamps and so I am able to control the updates to the chart myself. What I wanted to avoid was plotting points (i.e. markers) on the charts when I hadn't actually received any new data. As a quick cheap hack I have subclassed the XYStepLine render class to draw an extended line for the last point in the dataset. This line gets corrected as new points arrive for the series. I'm going to be looing at creating a type of chart data cache to allow replaying of old data and am likely to incorporate your suggestions into this service.
pjp
Excellent. Glad that was of use
Brian Agnew