JFreeChart Line graph plot OHLCDataItem [duplicate]
-
05-07-2021 - |
Question
Possible Duplicate:
Multiple OHLC datasets in one image
Hi So I have plotted a candleStick graph using a OHLCDataItem
array, and I am also plotting a line graph over the top using the same array, however at the moment the line graph plots the "open" variable of the OHLCDataItem
. How do I get it to plot a different variable.
i.e. the constructor is:
OHLCDataItem(java.util.Date date, double open, double high, double low, double close, double volume)
So currently this is my code setting up the graph:
List<OHLCDataItem> data = getData(stockSymbol);
OHLCDataItem[] dataItems = data.toArray(new OHLCDataItem[data.size()]);
XYDataset generalDataSet = new DefaultOHLCDataset(stockSymbol, dataItems);
XYPlot mainPlot = new XYPlot(generalDataSet, domainAxis, rangeAxis, candleStickRenderer);
mainPlot.setDataset(1, generalDataSet);
mainPlot.setRenderer(1, LineRenderer);
This line: mainPlot.setDataset(1, generalDataSet);
is setting up the plot for the line graph, but I cant figure out how to graph a different variable than "open". I think it must be straight forward, but I cant grasp it.
Solution
you probably want OHLCSeries and OHLCSeriesCollection (which implements XYDataset), instead of an OHLCDataItem array and DefaultOHLCDataset.