1

I'm trying to combine a XYBarChart as well as a normal XYPlot in a CombinedDomainXYPlot. The domain axis is a DateAxis(), allowing me to plot time series.

For the XYPlots, I can add datapoints dynamically using:

[XYSeries].add(time, value);

However, for the XYBarChart, I'm using JFreeChart's DefaultIntervalXYDataSet. For this class, the method for adding a data-series, is as follows:

addSeries(java.lang.Comparable seriesKey, double[][] data)

Adds a series or if a series with the same key already exists replaces the data for that series, then sends a DatasetChangeEvent to all registered listeners.

Clearly, the parameter double[][] data does not allow for dynamic changes to the data, in the sense that I can't simply add the new datapoints to the series itself. Is there a way to add datapoints to the XYBarChart dynamically? Or do I have to replace the complete double[][] in every update?

Ultimately, my goal is to add bars dynamically and give these bars a dynamic color.

Community
  • 1
  • 1
Jean-Paul
  • 19,910
  • 9
  • 62
  • 88
  • Can you share code that you already have, if any? – Freek de Bruijn Aug 11 '15 at 20:16
  • @FreekdeBruijn I had code but it didn't work so I deleted it. The barchart demo of jFreeChart is almost identical to my situation so perhaps we can try to make that one dynamic. – Jean-Paul Aug 11 '15 at 20:41
  • did you see http://stackoverflow.com/questions/11469865/making-dynamic-line-chart-using-jfree-chart-in-java, http://stackoverflow.com/questions/17528820/dynamic-chart-using-jfreechart, or http://www.java2s.com/Code/Java/Chart/JFreeChartDynamicDataDemo.htm? These pages appear to be promising at first glance. – Freek de Bruijn Aug 11 '15 at 20:49
  • Use `addSeries()` to replace the previous series with a new one, or extend `AbstractIntervalXYDataset` to allow updating in place. – trashgod Aug 11 '15 at 21:08

1 Answers1

2

Use an instance of org.jfree.data.xy.XYIntervalSeriesCollection. This dataset implements the IntervalXYDataset interface and allows the dynamic addition of further data items. The relationship between the DefaultIntervalXYDataSet and XYIntervalSeriesCollection is similar to that between DefaultXYDataset and XYSeriesCollection.

Jean-Paul
  • 19,910
  • 9
  • 62
  • 88
Soltub
  • 101
  • 2