CandlestickRenderer wrong width with SegmentedTimeline bug

Discussion about JFreeChart related to stockmarket charts.

CandlestickRenderer wrong width with SegmentedTimeline bug

Postby avarvit » Wed Apr 17, 2013 3:58 pm

Hello,

Apologies if this one is old. I use JFreeChart 1.0.13 (but I think the problem is unfixed in 1.0.14, too). I found that CandlestickRenderer using a SegmentedTimeline timeline was occasionally producing very thin candles. I tracked the problem in that the minimum candlestick width calculated in CandlestickRenderer.initialise() is wrong when the start date plus the default candle width (21 hours) falls into an exception segment (e.g. weekend).

I think that the following patch rectifies the problem, although not too elegantly:

File CandlestickRenderer.java, circa line 604:

Code: Select all
        // begin avarvit hack
        double xx2; //= axis.valueToJava2D(x2, dataArea, edge);
        // if we use SegmentedTimeline, it may happen that xx1 and xx2 coincide, because xx1 falls
        // into an exception segment; for this, we test if xx2 equals xx1 and if so we increase x2
        // until we get a non-zero difference
        do {
           xx2 = axis.valueToJava2D(x2, dataArea, edge);
           x2 += this.maxCandleWidthInMilliseconds;
        } while (xx2 == xx1);
        // end avarvit hack


The fix should be self-explanatory.

Regards,

Angelos
avarvit
 
Posts: 3
Joined: Mon May 21, 2012 3:07 pm

Return to JFreeChart - Stockmarket

Who is online

Users browsing this forum: No registered users and 3 guests