Candlestick bar outlines

Discussion about JFreeChart related to stockmarket charts.
Locked
fislamabak
Posts: 5
Joined: Fri Aug 08, 2008 10:25 pm
Location: Aberdeen, UK

Candlestick bar outlines

Post by fislamabak » Tue Sep 02, 2008 9:34 pm

Okay, this is a bit lengthy, just to avoid me creating multiple threads. Apologies!

I am using Jfreechart to render candlesticks. I find that using a black background results in better looking charts (see pix below). However with the black background, the wicks/shadows of the candlestick bars are not visible (see first image below).


I found a workaround this using the following:

Code: Select all

       
                candleRenderer.setUseOutlinePaint(true);
                candleRenderer.setSeriesOutlinePaint(0, Color.DARK_GRAY);
I have tried a number of outiline colors and Color.DARK_GRAY gives the best result. (see second image below).

My question is: Is there is a way to make the candle outline color the same as its fill color (ie switch outline color from red to green depending on the candle bodies fill color, rather than using a fixed outline color)? It appears by overiding the CandleRenderer.drawItem(. . . .) method this is possible but I dont fully understand the drawItem(...) method. If someone can show me how to achieve this, i would be very much grateful!

Also, on this thread (http://www.jfree.org/phpBB2/viewtopic.php?t=24952) , RoyW made the following remark:
If that doesn't work then it appears to be a bug in XYBarRenderer.
Here is the relevant code from XYBarRenderer Code:

....................

Unfortunately StartX will be a time that is less than the time segment so when it gets translated it gets truncated.
E.g.
Suppose your segment is 8am to 4pm
Your data is at 8.00
StartX = 8:00 - 1 min - 7:59
EndX = 8:00 + 1 min = 8:01

StartX lies outside the segment so it seems to be returning 8:00 for startX so the bar at the beginning of the segment is always thinner than the rest.

I would need to create a demo program to test the theory.
It would appear from my plots that RoyW's theory was right, as I notice volume bars on Mondays are thinner (see first image below). I was wondering if anyone has implemented a fix (overide method in XYBarRenderer subclass for example).


Thanks for your time.
Last edited by fislamabak on Tue Sep 02, 2008 9:40 pm, edited 2 times in total.

fislamabak
Posts: 5
Joined: Fri Aug 08, 2008 10:25 pm
Location: Aberdeen, UK

Post by fislamabak » Tue Sep 02, 2008 9:35 pm

.
FIRST IMAGE (wicks/shadows of candlesticks not visible)
.
.
Image

fislamabak
Posts: 5
Joined: Fri Aug 08, 2008 10:25 pm
Location: Aberdeen, UK

Post by fislamabak » Tue Sep 02, 2008 9:40 pm

.
SECOND IMAGE (wicks/shadows of candlesticks now visible because of outline color)
.
.
Image

RoyW
Posts: 93
Joined: Wed Apr 23, 2008 7:42 pm
Contact:

Post by RoyW » Fri Sep 05, 2008 3:16 pm

Try this for the colors.

Code: Select all

        CandlestickRenderer candleRenderer = new CandlestickRenderer(){
            public Paint getItemOutlinePaint(int row, int column) {
                OHLCDataset dataset = (OHLCDataset) getPlot().getDataset();

                double open  = dataset.getOpenValue(row, column);
                double close = dataset.getCloseValue(row, column);

                if(open > close){
                    return getDownPaint();
                } else {
                    return getUpPaint();
                }
            }
        };

Haven't got a fix for the bar width though.
The answer does not come from thinking outside the box, rather the answer comes from realizing the truth; There is no Box. my js site

fislamabak
Posts: 5
Joined: Fri Aug 08, 2008 10:25 pm
Location: Aberdeen, UK

Post by fislamabak » Fri Sep 05, 2008 8:41 pm

Many thanks RoyW. You just made my day!!!

Locked