是我没有说清楚——
我用一个Tchart绘几种不同类型的图,需要分别设置坐标,然后绘。运行后,多次读入文件并绘图后,就会出现前述异常。
问题可能出在对坐标的分别设置上,但我不知如何解决此问题,是否必须用多个Tchart?
全部代码如下:
procedure TMainform.N4Click(Sender: TObject); //引入数据文件
begin
chart1.visible:=false;
label1.caption:='';
if opendialog1.Execute then
begin
memo1.clear;
memo1.lines.loadfromfile(opendialog1.Filename);
end;
end;
procedure TMainform.N8Click(Sender: TObject); //绘图1
var
Sk,riqi0,riqi1:Tdatetime;
i,Nian,Yue,Ri,Shi,Fen,Miao:Integer;
y
ouble;
begin
if MEmo1.lines.count=0 then application.messagebox('请先引入文件!','提示',mb_ok)
else
begin
chart1.undozoom;
chart1.Visible :=true;
chart1.BackWall.Pen.Visible:=false;
chart1.Legend.Visible :=false;
chart1.width:=screen.Width ;
chart1.height:=screen.height div 2;
chart1.left:=(screen.width-chart1.width)div 2;
With Chart1.LeftAxis do
begin
Automatic := False ;
Minimum:= 0 ;
Maximum:= 0 ;
Minimum:= 0.0 ;
Maximum:=9.0;
AxisValuesFormat := '###0.0###';
title.caption:='M';
end;
With Chart1.BottomAxis do
begin
Automatic := False ;
Series1.XValues.DateTime := True;
Increment := DateTimeStep[dtOnehour];
DateSeparator := '/';
DateTimeFormat:='d/m/yyyy';
Minimum:= 0 ;
Maximum:= 0 ;
riqi0:=EncodeDate(strtoint(copy(memo1.lines[0],1,4)),strtoint(copy(memo1.lines[0],5,2)),strtoint(copy(memo1.lines[0],7,2)))
+EncodeTime(strtoint(copy(memo1.lines[0],9,2)),0,0,0);
riqi1:=EncodeDate(strtoint(copy(memo1.lines[memo1.lines.count-1],1,4)),strtoint(copy(memo1.lines[memo1.lines.count-1],5,2)),strtoint(copy(memo1.lines[memo1.lines.count-1],7,2)))
+EncodeTime(strtoint(copy(memo1.lines[memo1.lines.count-1],9,2)),strtoint(copy(memo1.lines[memo1.lines.count-1],11,2))+5,50,50);
Maximum:=riqi1;
Minimum:=riqi0;
end;
chart1.leftAxis.Grid.Visible :=false;
chart1.bottomAxis.Grid.Visible :=false;
series1.clear;
series2.clear;
series3.clear;
series4.clear;
series5.clear;
series6.clear;
series7.clear;
series8.clear;
series9.clear;
series10.clear;
for i:=0 to memo1.lines.count-1 do
begin
Nian:=strtoint(copy(memo1.lines
,1,4));
Yue:=strtoint(copy(Memo1.lines,5,2));
Ri:=strtoint(copy(Memo1.lines,7,2));
Shi:=strtoint(copy(Memo1.lines,9,2));
Fen:=strtoint(copy(Memo1.lines,11,2));
Miao:=strtoint(copy(Memo1.lines,13,2));
sk:=Encodedate(nian,yue,ri)+EncodeTime(shi,fen,miao,00);
y:=strtofloat(copy(memo1.lines,27,2))/10;
series8.addxy(sk,y,'',clteecolor);
end;
end;
end;
procedure TMainform.Et1Click(Sender: TObject); //绘图2
var
i,Nian,Yue,Ri,Shi,Fen,Miao:integer;
sk,riqi0,riqi1:tdatetime;
y:double;
MS:single;
begin
if MEmo1.lines.count=0 then application.messagebox('请先引入文件!','提示',mb_ok)
else
begin
chart1.undozoom;
chart1.Visible :=true;
chart1.BackWall.Pen.Visible:=false;
chart1.Legend.Visible :=false;
chart1.width:=screen.width;
chart1.height:=screen.height div 2;
chart1.left:=(screen.width-chart1.width)div 2;
With Chart1.LeftAxis do
begin
Automatic := False ;
Minimum:= 0 ;
Maximum:= 0 ;
Maximum:= 10000000;
Minimum:=-600000;
AxisValuesFormat := '###0.###';
title.caption:='E';
end;
With Chart1.BottomAxis do
begin
Automatic := False ;
Minimum:= 0 ;
Maximum:= 0 ;
Series1.XValues.DateTime := True;
Increment := DateTimeStep[dtOneHour];
DateSeparator := '/';
DateTimeFormat:='d/m/yyyy';
riqi0:=EncodeDate(strtoint(copy(memo1.lines[0],1,4)),strtoint(copy(memo1.lines[0],5,2)),strtoint(copy(memo1.lines[0],7,2)))
+EncodeTime(strtoint(copy(memo1.lines[0],9,2)),strtoint(copy(memo1.lines[0],11,2)),strtoint(copy(memo1.lines[0],13,2)),0);
riqi1:=EncodeDate(strtoint(copy(memo1.lines[memo1.lines.count-1],1,4)),strtoint(copy(memo1.lines[memo1.lines.count-1],5,2)),strtoint(copy(memo1.lines[memo1.lines.count-1],7,2)))
+EncodeTime(strtoint(copy(memo1.lines[memo1.lines.count-1],9,2)),strtoint(copy(memo1.lines[memo1.lines.count-1],11,2)),strtoint(copy(memo1.lines[memo1.lines.count-1],13,2)),50);
Maximum:=riqi1;
Minimum:=riqi0;
end;
chart1.leftAxis.Grid.Visible :=false;
chart1.bottomAxis.Grid.Visible :=false;
series1.clear;
series2.clear;
series3.clear;
series4.clear;
series5.clear;
series6.clear;
series7.clear;
series8.clear;
series9.clear;
series10.clear;
for i:=0 to memo1.lines.count-1 do
begin
Nian:=strtoint(copy(memo1.lines,1,4));
Yue:=strtoint(copy(Memo1.lines,5,2));
Ri:=strtoint(copy(Memo1.lines,7,2));
Shi:=strtoint(copy(Memo1.lines,9,2));
Fen:=strtoint(copy(Memo1.lines,11,2));
Miao:=strtoint(copy(Memo1.lines,13,2));
sk:=Encodedate(nian,yue,ri)+EncodeTime(shi,fen,miao,00);
Ms:=0.113*(strtofloat(copy(memo1.lines,27,2)))-1.08;
y:=sqrt(exp((4.8+1.5*Ms)*ln(10)));
series9.addxy(sk,y,'',clteecolor);
end;
end;
end;
procedure TMainform.N9Click(Sender: TObject); //绘图3
var
i:integer;
begin
if Memo1.lines.count=0 then application.messagebox('请先引入文件!','提示',mb_ok)
else
begin
chart1.undozoom;
chart1.Visible:=true;
chart1.BackWall.Pen.Visible:=true;
chart1.width:=(screen.width)*2 div 3;
chart1.height:=(screen.height)*2 div 3;
chart1.left:=(screen.width-chart1.width)div 2;
chart1.Legend.Visible :=true;
Series1.XValues.DateTime := false;
With Chart1.LeftAxis do
begin
Automatic := False ;
Minimum:= 0;
Maximum:= 0;
Maximum:=2+strtofloat(COPY(memo1.lines[0],16,4))/100;
Minimum:= (strtofloat(COPY(memo1.lines[0],16,4))/100)-2;
title.caption:='';
end;
Chart1.BottomAxis.Increment :=1;
chart1.leftAxis.Grid.Visible :=true;
chart1.bottomAxis.Grid.Visible :=true;
With Chart1.bottomAxis do
begin
Automatic := False ;
Minimum:= 0;
Maximum:= 0;
Maximum:= 2+strtofloat(COPY(memo1.lines[1],20,5))/100;
Minimum:= (strtofloat(COPY(memo1.lines[1],20,5))/100)-2;
end;
series1.clear;
series2.clear;
series3.clear;
series4.clear;
series5.clear;
series6.clear;
series7.clear;
series8.clear;
series9.clear;
series10.clear;
for i:=0 to memo1.lines.count-1 do
begin
case strtoint(copy(memo1.lines,27,2)) of
1..19:series10.addxy(strtofloat(COPY(memo1.lines,20,3))+strtofloat(COPY(memo1.lines,23,2))/60,strtofloat(COPY(memo1.lines,16,2))+strtofloat(COPY(memo1.lines,18,2))/60,'',clteecolor);
20..29:series7.AddXY(strtofloat(COPY(memo1.lines,20,3))+strtofloat(COPY(memo1.lines,23,2))/60,strtofloat(COPY(memo1.lines,16,2))+strtofloat(COPY(memo1.lines,18,2))/60,'',clteecolor);
30..39:series6.addxy(strtofloat(COPY(memo1.lines,20,3))+strtofloat(COPY(memo1.lines,23,2))/60,strtofloat(COPY(memo1.lines,16,2))+strtofloat(COPY(memo1.lines,18,2))/60,'',clteecolor);
40..49:series5.addxy(strtofloat(COPY(memo1.lines,20,3))+strtofloat(COPY(memo1.lines,23,2))/60,strtofloat(COPY(memo1.lines,16,2))+strtofloat(COPY(memo1.lines,18,2))/60,'',clteecolor);
50..59:series4.addxy(strtofloat(COPY(memo1.lines,20,3))+strtofloat(COPY(memo1.lines,23,2))/60,strtofloat(COPY(memo1.lines,16,2))+strtofloat(COPY(memo1.lines,18,2))/60,'',clteecolor);
60..69:series3.addxy(strtofloat(COPY(memo1.lines,20,3))+strtofloat(COPY(memo1.lines,23,2))/60,strtofloat(COPY(memo1.lines,16,2))+strtofloat(COPY(memo1.lines,18,2))/60,'',clteecolor);
70..79:series2.addxy(strtofloat(COPY(memo1.lines,20,3))+strtofloat(COPY(memo1.lines,23,2))/60,strtofloat(COPY(memo1.lines,16,2))+strtofloat(COPY(memo1.lines,18,2))/60,'',clteecolor);
80..90:series1.addxy(strtofloat(COPY(memo1.lines,20,3))+strtofloat(COPY(memo1.lines,23,2))/60,strtofloat(COPY(memo1.lines,16,2))+strtofloat(COPY(memo1.lines,18,2))/60,'',clteecolor);
else
end;
end;
end;
end;