How do I get no gaps between candlesticks?

Discussion about JFreeChart related to stockmarket charts.
Locked
ptd26
Posts: 27
Joined: Sun Nov 08, 2009 10:12 am
antibot: No, of course not.

How do I get no gaps between candlesticks?

Post by ptd26 » Tue Sep 28, 2010 5:27 am

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?

ptd26
Posts: 27
Joined: Sun Nov 08, 2009 10:12 am
antibot: No, of course not.

Re: How do I get no gaps between candlesticks?

Post by ptd26 » Wed Sep 29, 2010 4:51 am

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...

dagaz
Posts: 1
Joined: Sat Feb 11, 2012 10:51 am
antibot: No, of course not.

Re: How do I get no gaps between candlesticks?

Post by dagaz » Sat Feb 11, 2012 10:53 am

I have fixed this with this line of code:

Code: Select all

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

Locked