home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / TeeChartPro / TeeChart5Delphi5Eval.exe / %MAINDIR% / Examples / Features / Candle_AxisLabels.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-10  |  2.4 KB  |  92 lines

  1. unit Candle_AxisLabels;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Base, TeEngine, Series, OHLChart, CandleCh, ExtCtrls, TeeProcs, Chart,
  8.   StdCtrls;
  9.  
  10. type
  11.   TCandleAxisLabels = class(TBaseForm)
  12.     Series1: TCandleSeries;
  13.     procedure FormCreate(Sender: TObject);
  14.     procedure Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  15.       ValueIndex: Integer; var LabelText: String);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. implementation
  23.  
  24. {$R *.DFM}
  25.  
  26. procedure TCandleAxisLabels.FormCreate(Sender: TObject);
  27. var tmpOpen  : Double;
  28.     tmpClose : Double;
  29.     t        : Integer;
  30.     tmpYear  : Word;
  31.     tmpMonth : Word;
  32.     tmpDay   : Word;
  33. begin
  34.   inherited;
  35.   { no dates }
  36.   Series1.XValues.DateTime:=False;
  37.  
  38.   { fill the candle with random points }
  39.   tmpOpen:=Random(1000);
  40.  
  41.   Series1.Clear;
  42.   for t:=1 to 100 do
  43.   begin
  44.     tmpOpen :=tmpOpen+(Random(100)-50);
  45.     tmpClose:=tmpOpen-(Random(100)-50);
  46.  
  47.     { add the point }
  48.     Series1.AddCandle( t, tmpOpen, tmpOpen+Random(10),
  49.                           tmpClose-Random(10), tmpClose );
  50.  
  51.     { set the LABEL to be the date in "yyyymmdd" format }
  52.     DecodeDate(Date+t, tmpYear, tmpMonth, tmpDay );
  53.     Series1.XLabel[ Series1.Count-1 ]:= FormatFloat('0000',tmpYear)+
  54.                                         FormatFloat('00',tmpMonth)+
  55.                                         FormatFloat('00',tmpDay);
  56.   end;
  57. end;
  58.  
  59. { The Chart OnGetAxisLabel event }
  60. procedure TCandleAxisLabels.Chart1GetAxisLabel(Sender: TChartAxis;
  61.   Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
  62. var tmpM : Integer;
  63. begin
  64.  
  65.   { show the month name or the day number }
  66.  
  67.   if Sender=Series1.GetHorizAxis then
  68.   if (Series1.Count>0) and (ValueIndex<>-1) then
  69.   begin
  70.     if (Sender.Maximum-Sender.Minimum)>30 then { more than one month }
  71.     begin
  72.       tmpM:=StrToInt(Copy(Series1.XLabel[ValueIndex],5,2));
  73.  
  74.       { first label }
  75.       if ValueIndex=0 then
  76.          LabelText:=ShortMonthNames[tmpM]
  77.       else
  78.       { other labels }
  79.       if StrToInt(Copy(Series1.XLabel[ValueIndex-1],5,2))<>tmpM then
  80.          LabelText:=ShortMonthNames[tmpM]
  81.       else
  82.          LabelText:='';
  83.     end
  84.     else { just day-of-the-month numbers }
  85.        LabelText:=Copy(Series1.XLabel[ValueIndex],7,2);
  86.   end;
  87. end;
  88.  
  89. initialization
  90.   RegisterClass( TCandleAxisLabels );
  91. end.
  92.