以下是我的子界面(也就是放chart控件的界面)代码unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Series, TeEngine, TeeFunci, TeeProcs, Chart, ExtCtrls; type TForm1 = class(TForm) Panel1: TPanel; Chart1: TChart; Series1: TBarSeries; Series6: TBarSeries; TeeFunction1: TAddTeeFunction; Series9: THorizBarSeries; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} Const LeftAixMin:Double=0; LeftAixMax:Double=90; BottAixMin:Double=0; BottAixMax:Double=30000; //定义 var WPL: array of integer; WCount: integer; Zao:array[8..120] of Double; procedure SetChartPointsCnt; var i:integer; begin Randomize; WCount:=150+Round(Random(10)); setlength(WPL,WCount); for i:=low(WPL) to high(WPL) do begin WPL[i]:=25*Trunc(Random(1200)); end; end; //Chart描点 procedure ChartAddPoints(Z:array of Double); var aWCQ:array of Double; i:integer; begin setlength(aWCQ,WCount); Randomize; Form1.Series1.Clear; for i:=0 to 1000 do Form1.Series1.AddXY(i,0,'',clLime); for i:=8 to 120 do begin Form1.Series1.AddXY(i*250000,Z[i],'',clLime); end; For i:=low(WPL) to High(WPL) do begin aWCQ[i]:=Random(70); Form1.Series1.AddXY(WPL[i],aWCQ[i],'',clLime); end; end; procedure TForm1.FormCreate(Sender: TObject); var i:integer; begin Form1.Chart1.LeftAxis.Minimum := LeftAixMin; Form1.Chart1.LeftAxis.Maximum := LeftAixMax; Form1.Chart1.BottomAxis.Maximum := BottAixMax; Form1.Chart1.BottomAxis.Minimum := BottAixMin; SetChartPointsCnt; for i:=8 to 120 do Zao[i]:=0; ChartAddPoints(Zao); Chart1.Show; end;procedure TForm1.Timer1Timer(Sender: TObject); begin ChartAddPoints(Zao); end;end.
以下我我主界面的代码unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type TForm3 = class(TForm) pnl1: TPanel; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form3: TForm3; implementation {$R *.dfm} uses Unit1; procedure TForm3.FormCreate(Sender: TObject); begin if Form1 = nil then begin Application.CreateForm(TForm1,Form1); end; Form1:=TForm1.Create(Application); Form1.ManualDock(pnl1,nil,alClient); Form1.Visible:=True; end; end.
procedure TForm3.FormCreate(Sender: TObject); begin if Form1 = nil then begin Application.CreateForm(TForm1,Form1); end; Form1:=TForm1.Create(Application); Form1.ManualDock(pnl1,nil,alClient); Form1.Visible:=True; end; 上面的代码有问题,修改一下:procedure TForm3.FormCreate(Sender: TObject); begin if not Assigned(Form1) then begin Form1:=TForm1.Create(Application); Form1.Parent := pnl1; Form1.Align := alClient; end; Form1.Show; end;
for i:=0 to 1000 do Form1.Series1.AddXY(i,0,'',clLime); for i:=8 to 120 do begin Form1.Series1.AddXY(i*250000,Z[i],'',clLime); end; For i:=low(WPL) to High(WPL) do begin aWCQ[i]:=Random(70); Form1.Series1.AddXY(WPL[i],aWCQ[i],'',clLime); end; 你这样写是什么意思,没看明白。 为了测试是否有数据,你可以把下面的屏蔽一下嘛,比如改成这样 for i:=0 to 1000 do Form1.Series1.AddXY(i,i,'',clLime);
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Series, TeEngine, TeeFunci, TeeProcs, Chart, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Chart1: TChart;
Series1: TBarSeries;
Series6: TBarSeries;
TeeFunction1: TAddTeeFunction;
Series9: THorizBarSeries;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Const
LeftAixMin:Double=0;
LeftAixMax:Double=90;
BottAixMin:Double=0;
BottAixMax:Double=30000; //定义
var
WPL: array of integer;
WCount: integer;
Zao:array[8..120] of Double;
procedure SetChartPointsCnt;
var
i:integer;
begin
Randomize; WCount:=150+Round(Random(10));
setlength(WPL,WCount);
for i:=low(WPL) to high(WPL) do
begin
WPL[i]:=25*Trunc(Random(1200));
end;
end;
//Chart描点
procedure ChartAddPoints(Z:array of Double);
var
aWCQ:array of Double;
i:integer;
begin setlength(aWCQ,WCount); Randomize; Form1.Series1.Clear; for i:=0 to 1000 do
Form1.Series1.AddXY(i,0,'',clLime);
for i:=8 to 120 do
begin
Form1.Series1.AddXY(i*250000,Z[i],'',clLime);
end;
For i:=low(WPL) to High(WPL) do
begin
aWCQ[i]:=Random(70);
Form1.Series1.AddXY(WPL[i],aWCQ[i],'',clLime);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
Form1.Chart1.LeftAxis.Minimum := LeftAixMin;
Form1.Chart1.LeftAxis.Maximum := LeftAixMax;
Form1.Chart1.BottomAxis.Maximum := BottAixMax;
Form1.Chart1.BottomAxis.Minimum := BottAixMin;
SetChartPointsCnt;
for i:=8 to 120 do Zao[i]:=0;
ChartAddPoints(Zao);
Chart1.Show;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
ChartAddPoints(Zao);
end;end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm3 = class(TForm)
pnl1: TPanel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
uses Unit1;
procedure TForm3.FormCreate(Sender: TObject);
begin
if Form1 = nil then
begin
Application.CreateForm(TForm1,Form1);
end;
Form1:=TForm1.Create(Application);
Form1.ManualDock(pnl1,nil,alClient);
Form1.Visible:=True;
end;
end.
procedure TForm3.FormCreate(Sender: TObject);
begin
if Form1 = nil then
begin
Application.CreateForm(TForm1,Form1);
end;
Form1:=TForm1.Create(Application);
Form1.ManualDock(pnl1,nil,alClient);
Form1.Visible:=True;
end;
上面的代码有问题,修改一下:procedure TForm3.FormCreate(Sender: TObject);
begin
if not Assigned(Form1) then
begin
Form1:=TForm1.Create(Application);
Form1.Parent := pnl1;
Form1.Align := alClient;
end;
Form1.Show;
end;
for i:=0 to 1000 do
Form1.Series1.AddXY(i,0,'',clLime);
for i:=8 to 120 do
begin
Form1.Series1.AddXY(i*250000,Z[i],'',clLime);
end;
For i:=low(WPL) to High(WPL) do
begin
aWCQ[i]:=Random(70);
Form1.Series1.AddXY(WPL[i],aWCQ[i],'',clLime);
end;
你这样写是什么意思,没看明白。
为了测试是否有数据,你可以把下面的屏蔽一下嘛,比如改成这样 for i:=0 to 1000 do
Form1.Series1.AddXY(i,i,'',clLime);