home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / STANDARD / LASTVALU.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  3.5 KB  |  125 lines

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Digital Series and Legend Last Values Demo  }
  4. { Copyright (c) 1995-1996 by David Berneda    }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. {$P-}   { <-- VERY IMPORTANT WHEN USING OnGet.. EVENTS }
  8. unit Lastvalu;
  9.  
  10. interface
  11. { This forms show 4 line series in "Stairs" mode.
  12.  
  13.  ( LineSeries1.Stairs := True ; )
  14.  
  15.   Legend Style is "lsLastValues" meaning the Legend will draw the
  16.   Last value for each Series.
  17. }
  18.  
  19. uses
  20.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  21.   Forms, Dialogs, Chart, Series, ExtCtrls, StdCtrls, Teengine, Buttons,
  22.   TeeProcs;
  23.  
  24. type
  25.   TDigitalForm = class(TForm)
  26.     Chart1: TChart;
  27.     LineSeries1: TLineSeries;
  28.     LineSeries2: TLineSeries;
  29.     LineSeries3: TLineSeries;
  30.     LineSeries4: TLineSeries;
  31.     Panel1: TPanel;
  32.     CheckBox1: TCheckBox;
  33.     Timer1: TTimer;
  34.     CheckBox2: TCheckBox;
  35.     CheckBox3: TCheckBox;
  36.     BitBtn3: TBitBtn;
  37.     CheckBox4: TCheckBox;
  38.     Memo1: TMemo;
  39.     procedure FormCreate(Sender: TObject);
  40.     procedure CheckBox1Click(Sender: TObject);
  41.     procedure Timer1Timer(Sender: TObject);
  42.     procedure CheckBox2Click(Sender: TObject);
  43.     procedure CheckBox3Click(Sender: TObject);
  44.     procedure Chart1GetLegendText(Sender: TCustomAxisPanel;
  45.       LegendStyle: TLegendStyle; Index: Longint; var LegendText: String);
  46.     procedure CheckBox4Click(Sender: TObject);
  47.   private
  48.     { Private declarations }
  49.   public
  50.     { Public declarations }
  51.   end;
  52.  
  53. implementation
  54.  
  55. {$R *.DFM}
  56.  
  57. procedure TDigitalForm.FormCreate(Sender: TObject);
  58. var t,tt:Longint;
  59. begin
  60.   Chart1.ApplyZOrder:=CheckBox4.Checked;     { ZOrder or not ZOrder... }
  61.   Chart1.Legend.Inverted:=True;
  62.   { Fill Series with random values }
  63.   for t:=0 to Chart1.SeriesCount-1 do
  64.   With Chart1.Series[t] do
  65.   begin
  66.     Clear;
  67.     for tt:=1 to 100 do Add( 2*t+Random(2), '', clTeeColor);
  68.   end;
  69. end;
  70.  
  71. procedure TDigitalForm.CheckBox1Click(Sender: TObject);
  72. begin
  73.   Timer1.Enabled:=CheckBox1.Checked;  { start / stop animation }
  74. end;
  75.  
  76. procedure TDigitalForm.Timer1Timer(Sender: TObject);
  77. var t:Longint;
  78. begin
  79.   Timer1.Enabled:=False;  { <-- stop the timer }
  80.  
  81.   { Now, add a new point to each Series }
  82.   for t:=0 to Chart1.SeriesCount-1 do
  83.   With Chart1.Series[t] do Add( 2*t+Random(2),'',clTeeColor);
  84.  
  85.   { Scroll the Horizontal Axis }
  86.   With Chart1.BottomAxis do  { <-- with the Horizontal Axis... }
  87.   Begin
  88.     Automatic := False;        { <-- we dont want automatic scaling }
  89.     Maximum := LineSeries1.XValues.Last;
  90.     Minimum := Maximum - 100;   { we want to see the last 100 points only }
  91.   End;
  92.   { re-start timer }
  93.   Timer1.Enabled:=True;
  94. end;
  95.  
  96. procedure TDigitalForm.CheckBox2Click(Sender: TObject);
  97. begin
  98.   Chart1.View3D:=CheckBox2.Checked;
  99. end;
  100.  
  101. procedure TDigitalForm.CheckBox3Click(Sender: TObject);
  102. begin
  103.   if CheckBox3.Checked then
  104.      Chart1.Legend.LegendStyle:=lsLastValues
  105.   else
  106.      Chart1.Legend.LegendStyle:=lsAuto;
  107. end;
  108.  
  109. procedure TDigitalForm.Chart1GetLegendText(Sender: TCustomAxisPanel;
  110.   LegendStyle: TLegendStyle; Index: Longint; var LegendText: String);
  111. begin
  112.   { we want to show the Series Title as well as the Last Values }
  113.   if LegendStyle=lsLastValues then
  114.      LegendText:=LegendText+' --> '+Chart1.Series[Index].Title;
  115. end;
  116.  
  117. procedure TDigitalForm.CheckBox4Click(Sender: TObject);
  118. begin
  119.   Chart1.ApplyZOrder:=CheckBox4.Checked;
  120.   Chart1.Repaint;
  121. end;
  122.  
  123.  
  124. end.
  125.