Question about XYDifferenceRenderer

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
gerlun
Posts: 9
Joined: Mon Feb 11, 2008 4:32 pm

Question about XYDifferenceRenderer

Post by gerlun » Sat Mar 08, 2008 7:04 pm

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!

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Sat Mar 08, 2008 7:25 pm

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.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

gerlun
Posts: 9
Joined: Mon Feb 11, 2008 4:32 pm

Post by gerlun » Sun Mar 09, 2008 6:25 am

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.
Thx for your reply!

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

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Sun Mar 09, 2008 8:52 am

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
You will have to create the plot manually (see the API for XYPlot).

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

gerlun
Posts: 9
Joined: Mon Feb 11, 2008 4:32 pm

Post by gerlun » Sun Mar 09, 2008 10:46 am

RichardWest wrote:
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
You will have to create the plot manually (see the API for XYPlot).

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(...));
Thx!!! I'll give it a try!

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Tue Mar 11, 2008 11:11 pm

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

Locked