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

  1. {*********************************************}
  2. {  TeeChart Pro 4 example                     }
  3. {  Copyright (c) 1995-1998 by David Berneda   }
  4. {  All rights reserved                        }
  5. {*********************************************}
  6. unit FastDraw;
  7. {$I teedefs.inc}
  8.  
  9. interface
  10.  
  11. { Shows how to custom draw lines to a TChart Canvas,
  12.   *without* using Series. ( Drawing directly by code )
  13.  
  14.   You can draw anything you want, and using the conversion
  15.   methods to calculate from Your values to Screen pixels.
  16.  
  17.   Elapsed Time to draw 25000 lines is calculated.
  18.   Tipically 0.3 seconds on a Matrox video card + NT 4.0 + Delphi 3.0
  19.             0.5   ""         ""                   ""        ""   1.02
  20. }
  21.  
  22. uses
  23.   Wintypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  24.   StdCtrls, Buttons, TeEngine, Series, ExtCtrls, TeeProcs, Chart;
  25.  
  26. type
  27.   TFastDrawForm = class(TForm)
  28.     Chart1: TChart;
  29.     BitBtn2: TBitBtn;
  30.     Series1: TFastLineSeries;
  31.     Button1: TButton;
  32.     Memo1: TMemo;
  33.     procedure BitBtn2Click(Sender: TObject);
  34.     procedure FormCreate(Sender: TObject);
  35.     procedure Button1Click(Sender: TObject);
  36.   private
  37.     { Private declarations }
  38.   public
  39.     { Public declarations }
  40.     Procedure DrawManyLines;
  41.   end;
  42.  
  43. var
  44.   FastDrawForm: TFastDrawForm;
  45.  
  46. implementation
  47.  
  48. {$R *.DFM}
  49.  
  50. Procedure TFastDrawForm.DrawManyLines;
  51. var t,
  52.     tt     : Integer;
  53.     SomeX,
  54.     SomeY  : Longint;
  55. begin
  56.   With Chart1 do
  57.   begin
  58.     Canvas.Pen.Style:=psSolid;
  59.     Canvas.Pen.Width:=1;
  60.     for t:=0 to 4 do  { draw 5 bands of lines }
  61.     begin
  62.       { calc X position of first point }
  63.       SomeX:=BottomAxis.CalcXPosValue(0);
  64.  
  65.       { calc Y position of first point }
  66.       SomeY:=LeftAxis.CalcYPosValue( t*200+ Random( 100 ) );
  67.  
  68.       { move to first point }
  69.       Canvas.MoveTo( SomeX, SomeY );
  70.  
  71.       { set a default color for points }
  72.       Canvas.Pen.Color:=GetDefaultColor(t);
  73.  
  74.       { draw many points ! }
  75.       for tt:=1 to 5000 do
  76.       begin
  77.         SomeX:= BottomAxis.CalcXPosValue( tt );
  78.         SomeY:= LeftAxis.CalcYPosValue( t*200+ Random( 100 ) );
  79.         Canvas.LineTo( SomeX, SomeY );
  80.       end;
  81.     end;
  82.   end;
  83. end;
  84.  
  85. procedure TFastDrawForm.BitBtn2Click(Sender: TObject);
  86. var t1:{$IFDEF D4}LongWord{$ELSE}Longint{$ENDIF};
  87. begin
  88.   { clear the Chart }
  89.   Chart1.Repaint;
  90.  
  91.   { store the current time }
  92.   t1:=GetTickCount;
  93.  
  94.   { do the big thing ! }
  95.   DrawManyLines;
  96.  
  97.   { show the user the time in seconds... }
  98.   ShowMessage( 'Time to draw 25000 lines: '+
  99.                FloatToStr((GetTickCount-t1)/1000.0)+' seconds!');
  100. end;
  101.  
  102. procedure TFastDrawForm.FormCreate(Sender: TObject);
  103. begin
  104.  { set the Chart Axis scales to hold all points... }
  105.   Chart1.BottomAxis.SetMinMax( 0, 5000 );
  106.   Chart1.LeftAxis.SetMinMax( 0, 1000 );
  107. end;
  108.  
  109. procedure TFastDrawForm.Button1Click(Sender: TObject);
  110. begin
  111.   Close;
  112. end;
  113.  
  114. end.
  115.