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

  1. unit Function_MovAve;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Base, ExtCtrls, TeeProcs, TeEngine, Chart, StdCtrls, ComCtrls, StatChar,
  8.   CurvFitt, Series;
  9.  
  10. type
  11.   TMovAveFunctionForm = class(TBaseForm)
  12.     CheckBox1: TCheckBox;
  13.     Label1: TLabel;
  14.     Label2: TLabel;
  15.     Label3: TLabel;
  16.     CheckBox3: TCheckBox;
  17.     Edit1: TEdit;
  18.     UpDown1: TUpDown;
  19.     Edit2: TEdit;
  20.     UpDown2: TUpDown;
  21.     Edit3: TEdit;
  22.     UpDown3: TUpDown;
  23.     ExpAve1: TLineSeries;
  24.     MovingAve1: TLineSeries;
  25.     MovingAve2: TLineSeries;
  26.     Curve1: TLineSeries;
  27.     Timer1: TTimer;
  28.     PriceLine: TLineSeries;
  29.     ExpAverageFunction1 : TExpAverageFunction;
  30.     MovingAverageFunction1: TMovingAverageFunction;
  31.     MovingAverageFunction2: TMovingAverageFunction;
  32.     procedure CheckBox1Click(Sender: TObject);
  33.     procedure Timer1Timer(Sender: TObject);
  34.     procedure Edit2Change(Sender: TObject);
  35.     procedure Edit3Change(Sender: TObject);
  36.     procedure Edit1Change(Sender: TObject);
  37.     procedure CheckBox3Click(Sender: TObject);
  38.     procedure FormCreate(Sender: TObject);
  39.   private
  40.     { Private declarations }
  41.   public
  42.     { Public declarations }
  43.   end;
  44.  
  45. implementation
  46.  
  47. {$R *.DFM}
  48.  
  49. procedure TMovAveFunctionForm.CheckBox1Click(Sender: TObject);
  50. begin
  51.   Timer1.Enabled:=CheckBox1.Checked; { <-- animation on / off }
  52. end;
  53.  
  54. procedure TMovAveFunctionForm.Timer1Timer(Sender: TObject);
  55. begin
  56.   Timer1.Enabled:=False;
  57.   With PriceLine do
  58.   Begin
  59.     Delete(0); { <-- remove the first point }
  60.  
  61.     { If the MovingAverage RecalcOptions property contains the [rOnDelete]
  62.       recalc option (the default), then the MovingAverages will be
  63.       cleared and recalculated automatically.
  64.  
  65.       But, if not (speed improvement), we should manually remove the
  66.       first MovingAverage point and force recalculation.
  67.     }
  68.     if not (rOnDelete in MovingAve1.RecalcOptions) then
  69.        MovingAve1.Delete(0);
  70.     if not (rOnDelete in MovingAve2.RecalcOptions) then
  71.        MovingAve2.Delete(0);
  72.  
  73.     { Add a new random point }
  74.     AddXY( XValues.Last+1,
  75.            YValues.Last+(Random(ChartSamplesMax)-(ChartSamplesMax/2)),
  76.            '',clTeeColor);
  77.  
  78.     { Recalculate Averages }
  79.     RefreshSeries;
  80.   end;
  81.   Timer1.Enabled:=True;
  82. end;
  83.  
  84. procedure TMovAveFunctionForm.Edit2Change(Sender: TObject);
  85. begin
  86.   MovingAve1.FunctionType.Period:=UpDown2.Position;
  87. end;
  88.  
  89. procedure TMovAveFunctionForm.Edit3Change(Sender: TObject);
  90. begin
  91.   MovingAve2.FunctionType.Period:=UpDown3.Position;
  92. end;
  93.  
  94. procedure TMovAveFunctionForm.Edit1Change(Sender: TObject);
  95. begin
  96.   ExpAverageFunction1.Weight:=(UpDown1.Position/100.0); { <-- change exponential weight }
  97. end;
  98.  
  99. procedure TMovAveFunctionForm.CheckBox3Click(Sender: TObject);
  100. begin
  101.   { switch between 2D and 3D and start animating... }
  102.   With Chart1 do
  103.   begin
  104.     View3D:=CheckBox3.Checked;
  105.     AxisVisible:=not View3D;
  106.     View3dWalls:=not View3D;
  107.     Chart3dPercent:=20;
  108.     ClipPoints:=not View3D;
  109.     Frame.Visible:=not View3D;
  110.     Title.Visible:=not View3D;
  111.     Foot.Visible:=not View3D;
  112.     Gradient.Visible:=View3D;
  113.     if View3D then
  114.        Legend.Alignment:=laBottom
  115.     else
  116.        Legend.Alignment:=laLeft;
  117.     UndoZoom;
  118.   end;
  119.  
  120.   if CheckBox3.Checked then CheckBox1.Checked:=True;
  121. end;
  122.  
  123. procedure TMovAveFunctionForm.FormCreate(Sender: TObject);
  124. begin
  125.   inherited;
  126.  
  127.   { tell the moving averages not to recalculate when
  128.     we will delete points... }
  129.   With MovingAve1 do RecalcOptions:=RecalcOptions-[rOnDelete];
  130.   With MovingAve2 do RecalcOptions:=RecalcOptions-[rOnDelete];
  131.  
  132.   PriceLine.FillSampleValues(200); { <-- Some random points }
  133. end;
  134.  
  135. initialization
  136.   RegisterClass(TMovAveFunctionForm);
  137. end.
  138.