home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / STANDARD / USCROLL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  4.5 KB  |  149 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.       AutomaticMaximum := False;        { <-- we dont want automatic scaling }
  52.       AutomaticMinimum := False;        { <-- we dont want automatic scaling }
  53.  
  54.       { In this example, we will set the Axis Minimum and Maximum values to
  55.         show One Hour of data ending at last point Time plus 5 minutes
  56.       }
  57.       Minimum := 0;
  58.       Maximum := Sender.YValues.MaxValue + DateTimeStep[ dtFiveMinutes ];
  59.       Minimum := Maximum - DateTimeStep[ dtOneHour ];
  60.     end;
  61.   end
  62.   else
  63.   begin
  64.     With Sender.GetHorizAxis do  { <-- with the Horizontal Axis... }
  65.     Begin
  66.       Automatic := False;        { <-- we dont want automatic scaling }
  67.       AutomaticMaximum := False;        { <-- we dont want automatic scaling }
  68.       AutomaticMinimum := False;        { <-- we dont want automatic scaling }
  69.  
  70.       { In this example, we will set the Axis Minimum and Maximum values to
  71.         show One Hour of data ending at last point Time plus 5 minutes
  72.       }
  73.       Minimum := 0;
  74.       Maximum := Sender.XValues.MaxValue + DateTimeStep[ dtFiveMinutes ];
  75.       Minimum := Maximum - DateTimeStep[ dtOneHour ];
  76.     end;
  77.   End;
  78. end;
  79.  
  80. Procedure TScrollForm.AddPoint(Const x,y:Double; AColor:TColor);
  81. begin
  82.   if CBVertical.Checked then { If VERTICAL SCROLL }
  83.      LineSeries1.AddXY(y,x,'',AColor)
  84.   else
  85.      LineSeries1.AddXY(x,y,'',AColor);
  86. end;
  87.  
  88. procedure TScrollForm.FormCreate(Sender: TObject);
  89. begin
  90.   FillDemoPoints;
  91. end;
  92.  
  93. procedure TScrollForm.FillDemoPoints;
  94. var t:Longint;
  95. begin
  96.    { fill the LineSeries with some random data }
  97.   LineSeries1.Clear;   { <-- this removes all points from LineSeries1 }
  98.  
  99.   { let's add 60 minutes from 12:00 to 12:59 }
  100.   for t:= 0 to 59 do
  101.       AddPoint( EncodeTime( 12, t, 0,0),Random(100),clRed );
  102.  
  103.   { let's add 60 more minutes from 13:00 to 13:59 }
  104.   for t:= 0 to 59 do
  105.       AddPoint( EncodeTime( 13, t, 0,0),Random(100),clRed);
  106. end;
  107.  
  108. procedure TScrollForm.Button1Click(Sender: TObject);
  109. var h,m,s,msec:word;
  110. begin
  111.   if CBVertical.Checked then { if VERTICAL SCROLL.... }
  112.      DecodeTime( LineSeries1.YValues.Last , h, m, s, msec)
  113.   else
  114.      DecodeTime( LineSeries1.XValues.Last , h, m, s, msec);
  115.  
  116.   { add a new random point to the Series (one more minute) }
  117.   inc(m);
  118.   if m=60 then
  119.   begin
  120.     m:=0;
  121.     inc(h);
  122.   end;
  123.   AddPoint( EncodeTime( h, m, s, msec), Random(100), clYellow );
  124. end;
  125.  
  126. procedure TScrollForm.CBVerticalClick(Sender: TObject);
  127. begin
  128.   With LineSeries1 do
  129.   if CBVertical.Checked then  { If VERTICAL SCROLL }
  130.   begin
  131.     YValues.Order:=loAscending;
  132.     XValues.Order:=loNone;
  133.     XValues.DateTime:=False;
  134.     YValues.DateTime:=True;
  135.   end
  136.   else
  137.   begin
  138.     XValues.Order:=loAscending;
  139.     YValues.Order:=loNone;
  140.     YValues.DateTime:=False;
  141.     XValues.DateTime:=True;
  142.   end;
  143.   Chart1.LeftAxis.Automatic:=True; { <-- this makes axis scales AUTOMATIC AGAIN ! }
  144.   Chart1.BottomAxis.Automatic:=True; { <-- this makes axis scales AUTOMATIC AGAIN ! }
  145.   FillDemoPoints;   { <-- fill sample values again ! }
  146. end;
  147.  
  148. end.
  149.