Page 1 of 1

How do I get no gaps between candlesticks?

Posted: Tue Sep 28, 2010 5:27 am
by ptd26
I have a candlestick chart and I want the candlesticks to always be touching so that there's no gaps between adjacent sticks. This question is not about accounting for missing time. It is simply about how do I get the candlesticks to be as large as possible without overlapping each other? I am using these settings:

setAutoWidthGap(0);
setAutoWidthFactor(1);

Which I thought would produce the candlesticks so that they are as large as possible, touching, but not overlapping at any zoom (so that the width grows and shrinks as one zooms in / out). However, what I get is overlapping candlesticks on the full zoom-out and candlesticks where the gap space is bigger than the candle width on full zoom-in. How do I get always touching, but not overlapping sticks?

Re: How do I get no gaps between candlesticks?

Posted: Wed Sep 29, 2010 4:51 am
by ptd26
I figured it out. You do want to set:

setAutoWidthGap(0);
setAutoWidthFactor(1);

As I had below. However, the reason there are gaps when zooming in is due to this:

case WIDTHMETHOD_AVERAGE:
itemCount = highLowData.getItemCount(series);
if (horiz) {
xxWidth = dataArea.getHeight() / itemCount;
}
else {
xxWidth = dataArea.getWidth() / itemCount;
}
break;

(Found inside CandleStick Renderer's drawItem routine.)

Problem is that itemCount is the count of total number of items in dataset and not the number of visible items. I fixed this by adding a parameter to drawItem and passing in the number of items to render. It now works perfectly, except when fully zoomed out...the items do not draw all the way to the right boundary so there's a bit of overlapping. But close enough...

Re: How do I get no gaps between candlesticks?

Posted: Sat Feb 11, 2012 10:53 am
by dagaz
I have fixed this with this line of code:

Code: Select all

itemCount = state.getLastItemIndex() - state.getFirstItemIndex();