home *** CD-ROM | disk | FTP | other *** search
- unit UCandle;
- {$P-} { <-- only for Delphi 1.0 }
-
- interface
-
- { This project shows how to use the Candle Series programatically,
- to remove Weekends from the bottom axis.
- }
- uses
- Wintypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- TeEngine, Series, OHLChart, CandleCh, ExtCtrls, TeeProcs, Chart, StdCtrls;
-
- type
- TCandleWeekForm = class(TForm)
- Chart1: TChart;
- Series1: TCandleSeries;
- Button1: TButton;
- RadioGroup1: TRadioGroup;
- Memo1: TMemo;
- procedure FormCreate(Sender: TObject);
- procedure Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
- ValueIndex: Longint; var LabelText: String);
- procedure Series1BeforeDrawValues(Sender: TObject);
- procedure RadioGroup1Click(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- CandleWeekForm: TCandleWeekForm;
-
- implementation
-
- {$R *.DFM}
-
- { My Sample Data }
- const MyOpen:Array[0..10] of Double=(100,110,120,130,140,150,160,170,160,150,140);
- MyHigh:Array[0..10] of Double=(105,115,125,135,145,155,165,175,169,159,147);
- MyLow :Array[0..10] of Double=(95,105,115,125,135,145,155,165,158,149,130);
- MyClose:Array[0..10] of Double=(104,106,124,134,136,154,164,166,165,153,136);
-
- { Days of January 1998 }
- MyDate :Array[0..10] of Integer=(5,6,7,8,9,12,13,14,15,16,19);
-
- procedure TCandleWeekForm.FormCreate(Sender: TObject);
- var t:Integer;
- begin
- { Add Candles to the Series... }
- for t:=0 to 10 do
- begin
- { use "t" instead of dates to remove weekends }
- Series1.AddCandle(t,MyOpen[t],MyHigh[t],MyLow[t],MyClose[t]);
-
- { change after the candle label "Mon", "Tue", "Wed", etc. }
-
- Series1.XLabel[t]:=ShortDayNames[DayOfWeek(EncodeDate(1998,1,MyDate[t]))];
- end;
-
- { some nice settings... }
- Series1.CandleWidth:=10;
- Series1.Pen.Width:=2;
- Chart1.View3D:=False;
-
- { change bottom axis labels font }
- Chart1.BottomAxis.LabelsFont.Style:=[fsBold];
- Chart1.BottomAxis.LabelsFont.Size:=12;
-
- Chart1.LeftAxis.Grid.Visible:=False;
-
- { change chart title... }
- With Chart1.Title.Text do
- begin
- Clear;
- Add('Candle Series without weekends');
- end;
-
- { change memo1 }
- With Memo1.Lines do
- begin
- Clear;
- for t:=1 to 7 do Add(ShortDayNames[t]+'='+IntToStr(t));
- end;
- Memo1.Visible:=False;
-
- end;
-
- procedure TCandleWeekForm.Chart1GetAxisLabel(Sender: TChartAxis;
- Series: TChartSeries; ValueIndex: Longint; var LabelText: String);
- begin
- { this event is used to paint the Mondays label in color RED }
- if ValueIndex>=0 then
- With Sender do
- if DayOfWeek(EncodeDate(1998,1,MyDate[ValueIndex]))=2 then
- begin
- LabelsFont.Color:=clRed;
- Grid.Color:=clRed;
- Grid.Style:=psSolid;
- end
- else
- begin
- LabelsFont.Color:=clBlack;
- Grid.Color:=clGray;
- Grid.Style:=psDot;
- end;
- end;
-
- procedure TCandleWeekForm.Series1BeforeDrawValues(Sender: TObject);
- var x1,x2:Integer;
- begin
- { this Series event is used to paint the "Week 1" and "Week 2" strings }
- With Chart1,Canvas do
- begin
- Font.Color:=clYellow;
- Font.Size:=14;
- TextAlign:=Ta_Center;
- x1:=BottomAxis.CalcPosValue(0);
- x2:=BottomAxis.CalcPosValue(5);
- TextOut((x1+x2) div 2,ChartRect.Bottom-30,'Week 1');
- x1:=BottomAxis.CalcPosValue(6);
- x2:=BottomAxis.CalcPosValue(10);
- TextOut((x1+x2) div 2,ChartRect.Bottom-30,'Week 2');
- TextAlign:=Ta_Left;
- end;
- end;
-
- procedure TCandleWeekForm.RadioGroup1Click(Sender: TObject);
- var s:String;
- TheDate:TDateTime;
- t:Integer;
- begin
- for t:=0 to Series1.Count-1 do
- begin
- TheDate:=EncodeDate(1998,1,MyDate[t]);
- Case RadioGroup1.ItemIndex of
- 0: s:=ShortDayNames[DayOfWeek(TheDate)];
- 1: s:=IntToStr(DayOfWeek(TheDate));
- 2: s:=IntToStr(MyDate[t]);
- 3: s:=FormatDateTime('dd-mm-yy',TheDate);
- 4: s:=FormatDateTime('mmm-dd',TheDate);
- end;
- Series1.XLabel[t]:=s;
- end;
-
- Memo1.Visible:=RadioGroup1.ItemIndex=1;
- end;
-
- procedure TCandleWeekForm.Button1Click(Sender: TObject);
- begin
- Close;
- end;
-
- end.
-