home *** CD-ROM | disk | FTP | other *** search
- {*********************************************}
- { TeeChart Pro 4 example }
- { Copyright (c) 1995-1998 by David Berneda }
- { All rights reserved }
- {*********************************************}
- unit FastDraw;
- {$I teedefs.inc}
-
- interface
-
- { Shows how to custom draw lines to a TChart Canvas,
- *without* using Series. ( Drawing directly by code )
-
- You can draw anything you want, and using the conversion
- methods to calculate from Your values to Screen pixels.
-
- Elapsed Time to draw 25000 lines is calculated.
- Tipically 0.3 seconds on a Matrox video card + NT 4.0 + Delphi 3.0
- 0.5 "" "" "" "" 1.02
- }
-
- uses
- Wintypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Buttons, TeEngine, Series, ExtCtrls, TeeProcs, Chart;
-
- type
- TFastDrawForm = class(TForm)
- Chart1: TChart;
- BitBtn2: TBitBtn;
- Series1: TFastLineSeries;
- Button1: TButton;
- Memo1: TMemo;
- procedure BitBtn2Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- Procedure DrawManyLines;
- end;
-
- var
- FastDrawForm: TFastDrawForm;
-
- implementation
-
- {$R *.DFM}
-
- Procedure TFastDrawForm.DrawManyLines;
- var t,
- tt : Integer;
- SomeX,
- SomeY : Longint;
- begin
- With Chart1 do
- begin
- Canvas.Pen.Style:=psSolid;
- Canvas.Pen.Width:=1;
- for t:=0 to 4 do { draw 5 bands of lines }
- begin
- { calc X position of first point }
- SomeX:=BottomAxis.CalcXPosValue(0);
-
- { calc Y position of first point }
- SomeY:=LeftAxis.CalcYPosValue( t*200+ Random( 100 ) );
-
- { move to first point }
- Canvas.MoveTo( SomeX, SomeY );
-
- { set a default color for points }
- Canvas.Pen.Color:=GetDefaultColor(t);
-
- { draw many points ! }
- for tt:=1 to 5000 do
- begin
- SomeX:= BottomAxis.CalcXPosValue( tt );
- SomeY:= LeftAxis.CalcYPosValue( t*200+ Random( 100 ) );
- Canvas.LineTo( SomeX, SomeY );
- end;
- end;
- end;
- end;
-
- procedure TFastDrawForm.BitBtn2Click(Sender: TObject);
- var t1:{$IFDEF D4}LongWord{$ELSE}Longint{$ENDIF};
- begin
- { clear the Chart }
- Chart1.Repaint;
-
- { store the current time }
- t1:=GetTickCount;
-
- { do the big thing ! }
- DrawManyLines;
-
- { show the user the time in seconds... }
- ShowMessage( 'Time to draw 25000 lines: '+
- FloatToStr((GetTickCount-t1)/1000.0)+' seconds!');
- end;
-
- procedure TFastDrawForm.FormCreate(Sender: TObject);
- begin
- { set the Chart Axis scales to hold all points... }
- Chart1.BottomAxis.SetMinMax( 0, 5000 );
- Chart1.LeftAxis.SetMinMax( 0, 1000 );
- end;
-
- procedure TFastDrawForm.Button1Click(Sender: TObject);
- begin
- Close;
- end;
-
- end.
-