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

  1. {****************************************}
  2. {    TeeChart. Mini-Charts Example       }
  3. { Copyright (c) 1995,96 by David Berneda }
  4. {    All Rights Reserved                 }
  5. {****************************************}
  6. unit Umain;
  7.  
  8. interface
  9.  
  10. { This project show some very small mini-charts and some animation }
  11. { That mini-charts could be useful as small data-monitors in your forms,
  12.   or reports }
  13. uses
  14.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  15.   Forms, Dialogs, Chart, Series, ExtCtrls, Teengine, TeeProcs;
  16.  
  17. type
  18.   TMiniForm = class(TForm)
  19.     LineSeries1: TLineSeries;
  20.     Panel1: TPanel;
  21.     Panel2: TPanel;
  22.     Chart1: TChart;
  23.     Chart2: TChart;
  24.     Chart3: TChart;
  25.     Chart4: TChart;
  26.     PieSeries1: TPieSeries;
  27.     AreaSeries1: TAreaSeries;
  28.     LineSeries2: TLineSeries;
  29.     BarSeries1: TBarSeries;
  30.     LineSeries3: TLineSeries;
  31.     Timer1: TTimer;
  32.     procedure FormCreate(Sender: TObject);
  33.     procedure FormResize(Sender: TObject);
  34.     procedure Timer1Timer(Sender: TObject);
  35.     procedure LineSeries2AfterDrawValues(Sender: TObject);
  36.     procedure LineSeries3AfterDrawValues(Sender: TObject);
  37.   private
  38.     { Private declarations }
  39.   public
  40.     { Public declarations }
  41.     PosChart1,PosChart4:Longint;  { used to draw vertical lines over charts }
  42.   end;
  43.  
  44. implementation
  45.  
  46. {$R *.DFM}
  47.  
  48. Const NumPoints=30;
  49.  
  50. procedure TMiniForm.FormCreate(Sender: TObject);
  51. begin
  52.   PosChart1:=-1;                    { starting position of vertical divider }
  53.   PosChart4:=NumPoints div 2;
  54.  
  55.   { Generate some random points ... }
  56.   LineSeries1.FillSampleValues(NumPoints);
  57.   PieSeries1.FillSampleValues(8);
  58.   AreaSeries1.FillSampleValues(NumPoints);
  59.   LineSeries2.FillSampleValues(NumPoints);
  60.   BarSeries1.FillSampleValues(6);
  61.   LineSeries3.FillSampleValues(NumPoints);
  62. end;
  63.  
  64. procedure TMiniForm.FormResize(Sender: TObject);
  65. begin
  66.   { Equally resize the panels to center charts }
  67.   Chart2.Height:=ClientHeight div 2;
  68.   Chart3.Height:=ClientHeight div 2;
  69.   Panel1.Width:=ClientWidth div 2;
  70. end;
  71.  
  72. procedure TMiniForm.Timer1Timer(Sender: TObject);
  73.  
  74.   { This procedure changes the Series values every second }
  75.   Procedure RefreshMonitorChart(Chart:TChart; Var PosChart:Longint);
  76.   var t:Longint;
  77.       LastValueWas:Double;
  78.   Begin
  79.     Inc(PosChart);
  80.     if PosChart >= NumPoints then PosChart:=0;
  81.     for t:=0 to Chart.SeriesCount-1 do
  82.     Begin
  83.       if PosChart=0 then
  84.       Begin
  85.         With Chart do { reset scales at the end of monitoring. }
  86.         Begin
  87.           LeftAxis.Automatic:=True;
  88.           LeftAxis.SetMinMax(MinYValue(LeftAxis),MaxYValue(LeftAxis));
  89.         end;
  90.         LastValueWas:=Chart.Series[t].YValues.Last;
  91.       end
  92.       else LastValueWas:=Chart.Series[t].YValue[PosChart-1];
  93.  
  94.       { change the value for a new random one }
  95.       Chart.Series[t].YValue[PosChart]:= LastValueWas+Random(ChartSamplesMax)-
  96.                                            (ChartSamplesMax div 2);
  97.     end;
  98.   end;
  99.  
  100. var tmpPos:Longint;
  101. begin
  102.   RefreshMonitorChart(Chart1,PosChart1);       { refresh chart1  }
  103.  
  104.   RefreshMonitorChart(Chart4,PosChart4);       { refresh chart4  }
  105.  
  106.   With PieSeries1 do RotationAngle:=(RotationAngle+1) mod 359;  { rotate pie }
  107.  
  108.   { change Bar Series values }
  109.   With BarSeries1 do
  110.   Begin
  111.     tmpPos:=Random(Count);
  112.     YValue[tmpPos]:=YValue[tmpPos]*(80.0+Random(40))/100.0;
  113.   end;
  114. end;
  115.  
  116. procedure TMiniForm.LineSeries2AfterDrawValues(Sender: TObject);
  117. begin
  118.   { this event draws the red divider in Chart1 }
  119.    if PosChart1>=0 then
  120.    With Chart1,Canvas do
  121.    Begin
  122.      Pen.Color:=clRed;
  123.      DoVertLine( Series[0].CalcXPos(PosChart1),  { x }
  124.                  ChartRect.Top+1,                { initial Y }
  125.                  ChartRect.Bottom-1              { ending Y }
  126.                );
  127.    end;
  128. end;
  129.  
  130. procedure TMiniForm.LineSeries3AfterDrawValues(Sender: TObject);
  131. begin
  132.   { this event draws the blue divider in Chart4 }
  133.    if PosChart4>=0 then
  134.    With Chart4,Canvas do
  135.    Begin
  136.      Pen.Color:=clBlue;
  137.      DoVertLine( Series[0].CalcXPos(PosChart4),  { x }
  138.                  ChartRect.Top+1,                { initial Y }
  139.                  ChartRect.Bottom-1              { ending Y }
  140.                 );
  141.    end;
  142. end;
  143.  
  144. end.
  145.