用Tchart画曲线,想让曲线能动态地显示最新的一段曲线,之前的曲线向左移出。看delphi自带的demo,看不懂
这是自带的demo->Teechart->teebasic的例子,看不懂这一段,能否讲解一二FunctionTDemoform.TheChart:TChart;begin...
这是自带的demo->Teechart->teebasic的例子,看不懂这一段,能否讲解一二
Function TDemoform.TheChart:TChart;
begin
with NoteBook1 do
result:=(Pages.Objects[PageIndex] as TPage).Controls[0] as TChart;
end;
procedure TDemoForm.Timer1Timer(Sender: TObject);
var t:Longint;
tmpX:Double;
begin
With NoteBook1 do
Case PageIndex of
0,3,4,6: With TheChart do
begin
for t:=0 to SeriesCount-1 do
With Series[t] do
begin
tmpX:=XValues[1]-XValues[0];
Delete(0);
AddXY( XValues.Last+tmpX,
YValues.Last+Random(100)-50,'',clTeeColor);
end;
end;
1,2,8: With TheChart do
begin
if (tmpTimes=-1) then
begin
tmpSeries:=Random(SeriesCount);
tmpIndex :=Random(Series[tmpSeries].Count);
tmpTimes :=Random(10);
tmpRandom:=2*Round(Random(50)-25.0);
end;
if tmpSeries<>-1 then
begin
if PageIndex=8 then
With (Series[tmpSeries] as TBubbleSeries) do
begin
tmpX:=RadiusValues[tmpIndex]+tmpRandom;
if tmpX>=2 then
begin
RadiusValues[tmpIndex]:=tmpX;
if tmpRandom>0 then tmpX:=XValues[tmpIndex]+1
else tmpX:=XValues[tmpIndex]-1;
XValues[tmpIndex]:=tmpX;
if Random(10)<5 then tmpX:=YValues[tmpIndex]+50
else tmpX:=YValues[tmpIndex]-50;
YValues[tmpIndex]:=tmpX;
end
else tmpTimes:=0;
end
else
With Series[tmpSeries].MandatoryValueList do
Value[tmpIndex]:=Value[tmpIndex]+tmpRandom;
Dec(tmpTimes);
Repaint;
end;
end;
5: (TheChart[0] as TPieSeries).Rotate(358);
end;
end; 展开
Function TDemoform.TheChart:TChart;
begin
with NoteBook1 do
result:=(Pages.Objects[PageIndex] as TPage).Controls[0] as TChart;
end;
procedure TDemoForm.Timer1Timer(Sender: TObject);
var t:Longint;
tmpX:Double;
begin
With NoteBook1 do
Case PageIndex of
0,3,4,6: With TheChart do
begin
for t:=0 to SeriesCount-1 do
With Series[t] do
begin
tmpX:=XValues[1]-XValues[0];
Delete(0);
AddXY( XValues.Last+tmpX,
YValues.Last+Random(100)-50,'',clTeeColor);
end;
end;
1,2,8: With TheChart do
begin
if (tmpTimes=-1) then
begin
tmpSeries:=Random(SeriesCount);
tmpIndex :=Random(Series[tmpSeries].Count);
tmpTimes :=Random(10);
tmpRandom:=2*Round(Random(50)-25.0);
end;
if tmpSeries<>-1 then
begin
if PageIndex=8 then
With (Series[tmpSeries] as TBubbleSeries) do
begin
tmpX:=RadiusValues[tmpIndex]+tmpRandom;
if tmpX>=2 then
begin
RadiusValues[tmpIndex]:=tmpX;
if tmpRandom>0 then tmpX:=XValues[tmpIndex]+1
else tmpX:=XValues[tmpIndex]-1;
XValues[tmpIndex]:=tmpX;
if Random(10)<5 then tmpX:=YValues[tmpIndex]+50
else tmpX:=YValues[tmpIndex]-50;
YValues[tmpIndex]:=tmpX;
end
else tmpTimes:=0;
end
else
With Series[tmpSeries].MandatoryValueList do
Value[tmpIndex]:=Value[tmpIndex]+tmpRandom;
Dec(tmpTimes);
Repaint;
end;
end;
5: (TheChart[0] as TPieSeries).Rotate(358);
end;
end; 展开
展开全部
这个是所有Chart的刷新,你只要看 page0,也就是底下这段。
原理是先删掉曲线第一笔的资料,再从後面插一笔新的,所以X轴数值要一直递增,
如果你要让X轴参数固定,可能先排在阵列里处理过,再餵到series 会比较好作。
Case PageIndex of
0,3,4,6:
With TheChart do
begin
for t:=0 to SeriesCount-1 do
With Series[t] do //指定绘制的曲线
begin
tmpX:=XValues[1]-XValues[0]; //取得X轴数值间隔
Delete(0); //删除曲线的第一笔数据
AddXY( //插入新的数据,会自动放在最後
XValues.Last+tmpX, //设定X轴数值
YValues.Last+Random(100)-50, //设定Y轴数值
'', //Label
clTeeColor); //曲线颜色
end;
end;
...
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询