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

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Custom Axis Drawing Demo                    }
  4. { Copyright (c) 1995-1996 by David Berneda    }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. unit Mulaxis;
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, StdCtrls, ExtCtrls, Teengine, Chart, Series, Buttons,
  14.   TeeProcs;
  15.  
  16. type
  17.   TCustomAxisForm = class(TForm)
  18.     Chart1: TChart;
  19.     LineSeries1: TLineSeries;
  20.     Panel1: TPanel;
  21.     CheckBox1: TCheckBox;
  22.     Timer1: TTimer;
  23.     BitBtn1: TBitBtn;
  24.     CheckBox2: TCheckBox;
  25.     PointSeries1: TPointSeries;
  26.     FastLineSeries1: TFastLineSeries;
  27.     DrawGrid: TCheckBox;
  28.     Memo1: TMemo;
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure LineSeries1AfterDrawValues(Sender: TObject);
  31.     procedure CheckBox1Click(Sender: TObject);
  32.     procedure Timer1Timer(Sender: TObject);
  33.     procedure CheckBox2Click(Sender: TObject);
  34.     procedure DrawGridClick(Sender: TObject);
  35.   private
  36.     { Private declarations }
  37.   public
  38.     { Public declarations }
  39.     XPercent,YPercent:Integer;
  40.   end;
  41.  
  42. implementation
  43.  
  44. {$R *.DFM}
  45.  
  46. procedure TCustomAxisForm.FormCreate(Sender: TObject);
  47.  
  48.   Procedure CreateRandomPoints(Series:TChartSeries);
  49.   var t,Old:Longint;
  50.   begin
  51.     With Series do
  52.     begin
  53.       Clear;
  54.       Old:=Longint(Random(1000));
  55.       for t:=1 to 100 do
  56.       begin
  57.         Inc(Old,Longint(Random(20))-10);
  58.         Add(Old,'',clTeeColor);
  59.       end;
  60.     end;
  61.   end;
  62.  
  63. begin
  64.   XPercent:=50;
  65.   YPercent:=50;
  66.   Randomize;
  67.   CreateRandomPoints(LineSeries1);
  68.   CreateRandomPoints(PointSeries1);
  69.   CreateRandomPoints(FastLineSeries1);
  70. end;
  71.  
  72. procedure TCustomAxisForm.LineSeries1AfterDrawValues(Sender: TObject);
  73. var posaxis:longint;
  74. begin
  75.   With Chart1 do
  76.   begin
  77.     { Calculate axis position and draw... }
  78.     PosAxis:=ChartRect.Left+Trunc(ChartWidth*YPercent/100.0);
  79.     LeftAxis.CustomDraw(posaxis-10,posaxis-40,posaxis,DrawGrid.Checked);
  80.  
  81.     PosAxis:=ChartRect.Left+Trunc(ChartWidth*(100.0-YPercent)/100.0);
  82.     LeftAxis.CustomDraw(posaxis-10,posaxis-40,posaxis,DrawGrid.Checked);
  83.  
  84.     PosAxis:=ChartRect.Top+Trunc(ChartHeight*XPercent/100.0);
  85.     BottomAxis.CustomDraw(posaxis+10,posaxis+40,posaxis,DrawGrid.Checked);
  86.  
  87.     PosAxis:=ChartRect.Top+Trunc(ChartHeight*(100.0-XPercent)/100.0);
  88.     BottomAxis.CustomDraw(posaxis+10,posaxis+40,posaxis,DrawGrid.Checked);
  89.   end;
  90. end;
  91.  
  92. procedure TCustomAxisForm.CheckBox1Click(Sender: TObject);
  93. begin
  94.   Chart1.AxisVisible:=not CheckBox1.Checked;
  95.   Timer1.Enabled:=CheckBox1.Checked;
  96. end;
  97.  
  98. procedure TCustomAxisForm.Timer1Timer(Sender: TObject);
  99. begin
  100.   if XPercent<95 then Inc(XPercent,5)
  101.                  else XPercent:=5;
  102.   if YPercent<97 then Inc(YPercent,3)
  103.                  else YPercent:=3;
  104.   Chart1.Repaint;
  105. end;
  106.  
  107. procedure TCustomAxisForm.CheckBox2Click(Sender: TObject);
  108. begin
  109.   Chart1.LeftAxis.Inverted:=CheckBox2.Checked;
  110.   Chart1.BottomAxis.Inverted:=CheckBox2.Checked;
  111. end;
  112.  
  113. procedure TCustomAxisForm.DrawGridClick(Sender: TObject);
  114. begin
  115.   Chart1.Repaint;
  116. end;
  117.  
  118. end.
  119.