home *** CD-ROM | disk | FTP | other *** search
/ PC Expert 29 / Pce29cd.iso / RUNIMAGE / DELPHI40 / DEMOS / TEECHART / USCROLL.PAS < prev    next >
Pascal/Delphi Source File  |  1998-06-16  |  4KB  |  141 lines

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Auto Axis scaling Demo                      }
  4. { Copyright (c) 1995-1996 by David Berneda    }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. unit Uscroll;
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, StdCtrls, Chart, Series, ExtCtrls, Teengine, Buttons,
  14.   TeeProcs;
  15.  
  16. type
  17.   TScrollForm = class(TForm)
  18.     Chart1: TChart;
  19.     LineSeries1: TLineSeries;
  20.     Panel1: TPanel;
  21.     Button1: TButton;
  22.     BitBtn3: TBitBtn;
  23.     CBVertical: TCheckBox;
  24.     procedure LineSeries1AfterAdd(Sender: TChartSeries;
  25.       ValueIndex: Longint);
  26.     procedure FormCreate(Sender: TObject);
  27.     procedure Button1Click(Sender: TObject);
  28.     procedure CBVerticalClick(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.     Procedure AddPoint(Const x,y:Double; AColor:TColor);
  34.     procedure FillDemoPoints;
  35.   end;
  36.  
  37. implementation
  38.  
  39. {$R *.DFM}
  40.  
  41. { This is the event we need to arrange Axis scale as new points are added. }
  42. procedure TScrollForm.LineSeries1AfterAdd(Sender: TChartSeries;
  43.   ValueIndex: Longint);
  44. begin
  45.  { If VERTICAL SCROLL }
  46.   if CBVertical.Checked then
  47.   begin
  48.     With Sender.GetVertAxis do  { <-- with the Vertical Axis... }
  49.     Begin
  50.       Automatic := False;        { <-- we dont want automatic scaling }
  51.  
  52.       { In this example, we will set the Axis Minimum and Maximum values to
  53.         show One Hour of data ending at last point Time plus 5 minutes
  54.       }
  55.       Minimum := 0;
  56.       Maximum := Sender.YValues.MaxValue + DateTimeStep[ dtFiveMinutes ];
  57.       Minimum := Maximum - DateTimeStep[ dtOneHour ];
  58.     end;
  59.   end
  60.   else
  61.   begin
  62.     With Sender.GetHorizAxis do  { <-- with the Horizontal Axis... }
  63.     Begin
  64.       Automatic := False;        { <-- we dont want automatic scaling }
  65.  
  66.       { In this example, we will set the Axis Minimum and Maximum values to
  67.         show One Hour of data ending at last point Time plus 5 minutes
  68.       }
  69.       Minimum := 0;
  70.       Maximum := Sender.XValues.MaxValue + DateTimeStep[ dtFiveMinutes ];
  71.       Minimum := Maximum - DateTimeStep[ dtOneHour ];
  72.     end;
  73.   End;
  74. end;
  75.  
  76. Procedure TScrollForm.AddPoint(Const x,y:Double; AColor:TColor);
  77. begin
  78.   if CBVertical.Checked then { If VERTICAL SCROLL }
  79.      LineSeries1.AddXY(y,x,'',AColor)
  80.   else
  81.      LineSeries1.AddXY(x,y,'',AColor);
  82. end;
  83.  
  84. procedure TScrollForm.FormCreate(Sender: TObject);
  85. begin
  86.   FillDemoPoints;
  87. end;
  88.  
  89. procedure TScrollForm.FillDemoPoints;
  90. var t:Longint;
  91. begin
  92.    { fill the LineSeries with some random data }
  93.   LineSeries1.Clear;   { <-- this removes all points from LineSeries1 }
  94.  
  95.   { let's add 60 minutes from 12:00 to 12:59 }
  96.   for t:= 0 to 59 do
  97.       AddPoint( EncodeTime( 12, t, 0,0),Random(100),clRed );
  98.  
  99.   { let's add 60 more minutes from 13:00 to 13:59 }
  100.   for t:= 0 to 59 do
  101.       AddPoint( EncodeTime( 13, t, 0,0),Random(100),clRed);
  102. end;
  103.  
  104. procedure TScrollForm.Button1Click(Sender: TObject);
  105. var h,m,s,msec:word;
  106. begin
  107.   if CBVertical.Checked then { if VERTICAL SCROLL.... }
  108.      DecodeTime( LineSeries1.YValues.Last , h, m, s, msec)
  109.   else
  110.      DecodeTime( LineSeries1.XValues.Last , h, m, s, msec);
  111.  
  112.   { add a new random point to the Series (one more minute) }
  113.   inc(m);
  114.   if m=60 then
  115.   begin
  116.     m:=0;
  117.     inc(h);
  118.   end;
  119.   AddPoint( EncodeTime( h, m, s, msec), Random(100), clYellow );
  120. end;
  121.  
  122. procedure TScrollForm.CBVerticalClick(Sender: TObject);
  123. begin
  124.   With LineSeries1 do
  125.   if CBVertical.Checked then  { If VERTICAL SCROLL }
  126.   begin
  127.     YValues.Order:=loAscending;
  128.     XValues.Order:=loNone;
  129.   end
  130.   else
  131.   begin
  132.     XValues.Order:=loAscending;
  133.     YValues.Order:=loNone;
  134.   end;
  135.   Chart1.LeftAxis.Automatic:=True; { <-- this makes axis scales AUTOMATIC AGAIN ! }
  136.   Chart1.BottomAxis.Automatic:=True; { <-- this makes axis scales AUTOMATIC AGAIN ! }
  137.   FillDemoPoints;   { <-- fill sample values again ! }
  138. end;
  139.  
  140. end.
  141.