例子:
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, TeEngine, TeeSurfa, TeeProcs, Chart,
TeeTools;
type
TForm1 = class(TForm)
Chart1: TChart;
ColorGrid: TColorGridSeries;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
ChartTool2: TMarksTipTool;
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure CheckBox3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
procedure UpdateTheChart;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{$IFNDEF CLR}
type
TListHack=class(TChartValueList);
{$ENDIF}
Const DemoPoints = 200;
var x : Integer= - 1;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
begin
ColorGrid.Clear;
ColorGrid.NumXValues := 0;
ColorGrid.NumZValues := 0;
x := -1;
end;
Timer1.Enabled:=CheckBox1.Checked;
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
ColorGrid.ReuseGridIndex := CheckBox2.Checked;
end;
procedure TForm1.CheckBox3Click(Sender: TObject);
begin
ColorGrid.SmoothBitmap := CheckBox3.Checked;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=False;
Timer1.Interval := 20;
Chart1.Axes.Left.Grid.Hide;
Chart1.Axes.Bottom.Grid.Hide;
ColorGrid.Pen.Hide;
(*
// Remove chart parts to improve drawing speed
Chart1.Legend.Hide;
Chart1.ClipPoints := False;
Chart1.Title.Hide;
*)
// Speed tricks:
ColorGrid.ReuseGridIndex := True;
Chart1.Axes.FastCalc := True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
UpdateTheChart;
Label1.Caption:='Size: '+IntToStr(ColorGrid.NumXValues)+' x '+IntToStr(ColorGrid.NumZValues);
end;
procedure TForm1.UpdateTheChart;
var y,z : integer;
Index : Integer;
begin
Index := ColorGrid.Count;
label2.Caption := IntToStr(Index div 200);
ColorGrid.BeginUpdate;
try
Inc(x);
for z := 0 to DemoPoints-1 do
begin
y := Random(100);
ColorGrid.AddXYZ(z,y,x );//,'',Random($FFFFFF));
end;
if Index >= 16000 then ColorGrid.Delete(0, 200);
// BEGIN SPEED OPTIMIZATIONS
(*
{$IFNDEF CLR}
TListHack(ColorGrid.XValues).RecalcStats(Index);
TListHack(ColorGrid.YValues).RecalcStats(Index);
TListHack(ColorGrid.ZValues).RecalcStats(Index);
{$ENDIF} *)
if ColorGrid.ReuseGridIndex then
ColorGrid.FillGridIndex(Index);
// END SPEED OPTIMIZATIONS
ColorGrid.Repaint;
finally
ColorGrid.EndUpdate;
end;
end;