How can multiple datasets be used with JFreeChart?
Asked Answered
S

1

5

How could I add to a plot an OHLCSeriesCollection and a TimeSeriesCollection , in order to represent their values in the same chart ?

Shading answered 2/7, 2009 at 18:25 Comment(0)
B
10

Both OHLCSeriesCollection and TimeSeriesCollection are based on XYDataset so you should be able to add them both to an XYPlot with something like the following:

JFreeChart chart = // create your XY chart here.
XYPlot plot = chart.getXYPlot();
OHLCSeriesCollection ohlsSeriesDataset = // create you ohlc dataset here.
TimeSeriesCollection timeSeriesDataset = // create you time dataset here.
AbstractXYItemRenderer olhsSeriesRenderer = // create your ohlc renderer here.
AbstractXYItemRenderer timeSeriesRenderer = // create your time renderer here.

plot.setDataset(0, ohlsSeriesDataset);
plot.setDataset(1, timeSeriesDataset);
plot.setRenderer(0, olhsSeriesRenderer);
plot.setRenderer(1, timeSeriesRenderer);

The type of renderer to use for olhsSeriesRenderer and timeSeriesRenderer really depends on the type of chart you want to generate so I cannot give you specifics here.

I have not tried this myself with XY datasets, but I have been able to do combine CategoryDatasets using this.

Bencion answered 2/7, 2009 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.