Page 1 of 1

Candle sticks and weekends

Posted: Fri Jul 17, 2009 2:07 pm
by 10549714
Hi

I have a candlestick chart where I add data using

Code: Select all

.AddCandle(date, open, max, min, close)
When I display the chart I get blanks for the weekend (so basically five values and then two blanks over and over again)

How can I compress it so it that hides the weekends?

I see in the doco that you suggest using an incremental integer instead of date and then use labels but I sometimes overlay two or three other charts and do a lot of logic to figure out the scale of the X axis based on the dates... But most of the time the Candle stick chart is displayed on it's own. There isn't another way than the incremental integer is there?

Re: Candle sticks and weekends

Posted: Fri Jul 17, 2009 2:17 pm
by narcis
Hi Marius,

No, there's no alternative I can think of for now. Which are the exact problems you are having one using several charts together? You may get date logic retrieving label values from the series.

Re: Candle sticks and weekends

Posted: Fri Jul 17, 2009 2:22 pm
by 10549714
Just wanted to avoid rewriting it all....

Thanks anyway :-)

Re: Candle sticks and weekends

Posted: Mon Jul 20, 2009 10:06 am
by 10549714
Narcis

Further to my earlier question....

I've now changed my code to AddCandle using a sequential number.

Code: Select all

i := sCustom1.AddCandle(sCustom1.Count, FieldByName('OpeningValue').AsFloat, dMax, dMin, FieldByName('ClosingValue').AsFloat);
sCustom1.Labels[i] := FormatDateTime('d mmm yy', Trunc(FieldByName('IndexDate').AsDateTime));
When it comes to adjusting the X axis I use the following

Code: Select all

chCustom.BottomAxis.Increment := 5;
chCustom.BottomAxis.MinorTickCount := 4;
chCustom.BottomAxis.LabelStyle := talText;
It displays the labels as dates but it no longer respects the Increment value. I've set it to display every 5 labels but it fits them in based on a best fit approach. If I comment out the LabelStyle line then the Increment is respected.

Any ideas?

Re: Candle sticks and weekends

Posted: Mon Jul 20, 2009 11:54 am
by yeray
Hi Marius,

Could you try with an increment like following?

Code: Select all

Chart1.BottomAxis.Increment := DateTimeStep[dtOneWeek];

Re: Candle sticks and weekends

Posted: Mon Jul 20, 2009 12:46 pm
by 10549714
Hi Yeray

Unfortunately your suggestion does not work. DateTimeStep[dtOneWeek] simply returns 7. I need the interval to be 5 as I have removed the weekends...
Either way, even if I wanted 7 as an interval, it is still not respected...

Marius

Re: Candle sticks and weekends

Posted: Mon Jul 20, 2009 2:04 pm
by yeray
Hi Marius,

Yes, excuse me. I haven't understood well the problem. Setting the bottom axis labels style to show the series labels text, the increment can't be used as normally. then I recommend you to use OnGetAxisLabel event to show or hide the text. Here you have an example:

Code: Select all

var LabelsCount: Integer;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Series1.Clear;
  Chart1.View3D := false;

  for i:=0 to 20 do
  begin
    series1.AddCandle(i, random*100+600, random*100+800, random*100, random*100+200);
    series1.Labels[i] := FormatDateTime('d mmm yy', Now-20+i);
  end;
end;

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
begin
  if (Sender = Chart1.Axes.Bottom) then
  begin
    if (LabelsCount mod 5 <> 0) then
      LabelText := '';

    LabelsCount := LabelsCount+1;
  end;
end;

procedure TForm1.Chart1BeforeDrawAxes(Sender: TObject);
begin
  LabelsCount := 2;
end;