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

  1. {$I TeeDefs.inc}
  2. unit Welcome;
  3.  
  4. { Animation of Pie and Bar / Line series... }
  5.  
  6. interface
  7.  
  8. uses
  9.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  10.   StdCtrls, TeEngine, Series, ExtCtrls, TeeProcs, Chart;
  11.  
  12. type
  13.   TWelcomeForm = class(TForm)
  14.     Chart1: TChart;
  15.     Series1: TPieSeries;
  16.     Timer1: TTimer;
  17.     Series2: TLineSeries;
  18.     Series3: TLineSeries;
  19.     Series4: TFastLineSeries;
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure Timer1Timer(Sender: TObject);
  22.     procedure FormShow(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.     Delta     : Integer;
  26.     DeltaRot  : Integer;
  27.     DeltaElev : Integer;
  28.     TheSeries : TChartSeries;
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33. implementation
  34.  
  35. {$R *.DFM}
  36.  
  37. procedure TWelcomeForm.FormCreate(Sender: TObject);
  38. begin
  39.   { constants to rotate... }
  40.   Delta:=1;
  41.   DeltaElev:=1;
  42.   DeltaRot:=1;
  43.  
  44.   { sample values... }
  45.   Series1.FillSampleValues(8);
  46.   Series2.FillSampleValues(30);
  47.   Series3.FillSampleValues(30);
  48.   Series4.FillSampleValues(50);
  49.  
  50.   { the series to animate... }
  51.   TheSeries:=Series1;
  52.  
  53.   { start with a very small view... }
  54.   Chart1.View3DOptions.Zoom:=1;
  55. end;
  56.  
  57. { Do animation... }
  58. procedure TWelcomeForm.Timer1Timer(Sender: TObject);
  59.  
  60.   { add a new point to the series and remove the first point }
  61.   Procedure AddPoint(ASeries:TChartSeries);
  62.   begin
  63.     with ASeries do
  64.     begin
  65.       AddXY(XValues.Last+1,YValues.Last+Random(20)-10 {$IFNDEF D4},'',clTeeColor{$ENDIF} );
  66.       Delete(0);
  67.     end;
  68.   end;
  69.  
  70. begin
  71.   Timer1.Enabled:=False;
  72.  
  73.   { Pie series, do rotation... }
  74.   if TheSeries is TPieSeries then
  75.   begin
  76.     With TheSeries as TPieSeries do
  77.          RotationAngle:=RotationAngle+2;
  78.   end
  79.   else
  80.   { scroll points... }
  81.   begin
  82.     AddPoint(Series2);
  83.     AddPoint(Series3);
  84.     AddPoint(Series4);
  85.     { change 3D view (rotation / elevation) ... }
  86.     With Chart1.View3DOptions do
  87.     begin
  88.       Elevation:=Elevation+DeltaElev;
  89.       if (Elevation>320) or (Elevation<280) then
  90.          DeltaElev:=-DeltaElev;
  91.       Rotation:=Rotation+DeltaRot;
  92.       if (Rotation>355) or (Rotation<272) then
  93.          DeltaRot:=-DeltaRot;
  94.     end;
  95.   end;
  96.   { change view Zoom... }
  97.   With Chart1.View3DOptions do
  98.   begin
  99.     Zoom:=Zoom+Delta;
  100.  
  101.     { reverse zoom-in / zoom-out }
  102.     if (Zoom>200) or (Zoom<2) then
  103.        Delta:=-Delta;
  104.  
  105.     { change from Pie to Lines... }
  106.     if Zoom>200 then
  107.     begin
  108.       Series1.Active:=False;
  109.       Series2.Active:=False;
  110.       Series3.Active:=False;
  111.       Series4.Active:=False;
  112.       if TheSeries=Series1 then
  113.       begin
  114.         TheSeries:=Series2;
  115.         Series2.Active:=True;
  116.         Series3.Active:=True;
  117.         Series4.Active:=True;
  118.         Chart1.View3DOptions.Perspective:=75;
  119.         Chart1.View3DOptions.Rotation:=300;
  120.       end
  121.       else
  122.       begin
  123.         TheSeries:=Series1;
  124.         Chart1.View3DOptions.Rotation:=360;
  125.         TheSeries.Active:=True;
  126.       end;
  127.     end;
  128.   end;
  129.   { re-start the timer... }
  130.   Timer1.Enabled:=True;
  131. end;
  132.  
  133. procedure TWelcomeForm.FormShow(Sender: TObject);
  134. begin
  135.   Timer1.Enabled:=True;  { start animation... }
  136. end;
  137.  
  138. initialization
  139.   RegisterClass(TWelcomeForm)
  140. end.
  141.