I created a Bollinger bands by retrieving data from database. Therefore, in a chart I hv a upper band and a lower band. In between I plotted the stock price of a particular stock. Totally three time series.
The problem is that when I use XYDifferenceRenderer to color the area bounded by two series, it chose to color the area between the upper band and the stock price.
How can I avoid it and color the area bounded by the upper band and the
lower band instead?
Thx a lot!
Question about XYDifferenceRenderer
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Actually, this is a bug in the XYDifferenceRenderer algorithm I introduced when I rewrote the algorithm to make it more flexible. The XYDifferenceRenderer should only accept one or two series. A greater number of series than two does not make sense for the renderer because you cannot intuitively diff multiple series.
Given that this bug exists since 23 April 2007, you can exploit it by having the two Bollinger bands as the first two series and your stock prices as the third series. I would not rely on this though because this bug will probably be fixed soon by either David or I. The best solution moving forward would be to use multiple datasets and multiple renderers for the the plot. The Bollinger bands would be in one dataset rendered with an XYDifferenceRenderer. The stock prices would be in another dataset rendered with an XYLineAndShapeRenderer.
Given that this bug exists since 23 April 2007, you can exploit it by having the two Bollinger bands as the first two series and your stock prices as the third series. I would not rely on this though because this bug will probably be fixed soon by either David or I. The best solution moving forward would be to use multiple datasets and multiple renderers for the the plot. The Bollinger bands would be in one dataset rendered with an XYDifferenceRenderer. The stock prices would be in another dataset rendered with an XYLineAndShapeRenderer.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Thx for your reply!RichardWest wrote:Actually, this is a bug in the XYDifferenceRenderer algorithm I introduced when I rewrote the algorithm to make it more flexible. The XYDifferenceRenderer should only accept one or two series. A greater number of series than two does not make sense for the renderer because you cannot intuitively diff multiple series.
Given that this bug exists since 23 April 2007, you can exploit it by having the two Bollinger bands as the first two series and your stock prices as the third series. I would not rely on this though because this bug will probably be fixed soon by either David or I. The best solution moving forward would be to use multiple datasets and multiple renderers for the the plot. The Bollinger bands would be in one dataset rendered with an XYDifferenceRenderer. The stock prices would be in another dataset rendered with an XYLineAndShapeRenderer.
so how can I use mutilple datasets on the same chart?
As I used ChartFactory to create a timeseries chart and it accepts only ONE dataset/TimeSeriesCollection with multiple TimeSeries
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
You will have to create the plot manually (see the API for XYPlot).gerlun wrote:so how can I use mutilple datasets on the same chart?
As I used ChartFactory to create a timeseries chart and it accepts only ONE dataset/TimeSeriesCollection with multiple TimeSeries
Code: Select all
XYPlot plot = new XYPlot();
// two datasets and two renderers
plot.setDataset(0, bollingerDataset);
plot.setDataset(1, stockDataset);
plot.setRenderer(0, new XYDifferenceRenderer());
plot.setRenderer(1, new XYLineAndShapeRenderer());
// both datasets share the same range and domain axes
plot.setDomainAxis(new DateAxis(...));
plot.setRangeAxis(new NumberAxis(...));
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Thx!!! I'll give it a try!RichardWest wrote:You will have to create the plot manually (see the API for XYPlot).gerlun wrote:so how can I use mutilple datasets on the same chart?
As I used ChartFactory to create a timeseries chart and it accepts only ONE dataset/TimeSeriesCollection with multiple TimeSeriesCode: Select all
XYPlot plot = new XYPlot(); // two datasets and two renderers plot.setDataset(0, bollingerDataset); plot.setDataset(1, stockDataset); plot.setRenderer(0, new XYDifferenceRenderer()); plot.setRenderer(1, new XYLineAndShapeRenderer()); // both datasets share the same range and domain axes plot.setDomainAxis(new DateAxis(...)); plot.setRangeAxis(new NumberAxis(...));
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
I have filed a bug so this does not fall off the radar (see JFreeChart bug 1912232).
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA