网址:http://blog.csdn.net/lailai186/article/details/38685963
代码:
procedure TForm1.SpeedButton1Click(Sender: TObject);
{$j+}
const myvar:integer=0;
{$j-}
var
i:Integer;
begin
try
if myvar mod 2 = 0 then
begin
tbChart.Title.Text.Text:='电池数据分布图';
tbChart.Color := clWhite;
// 修改图表部分的背景色可以通过BackColor属性来实现:
tbChart.BackColor := clGreen;
// 此外,TChart还提供了渐变的背景支持,通过Gradient控制:
tbChart.Gradient.Visible := True;
tbChart.Gradient.Direction := gdFromTopLeft;
tbChart.Gradient.StartColor := clGreen;
tbChart.Gradient.EndColor := clYellow;
tbChart.Series[0].Clear;
for i:=0 to 8 do
begin
tbChart.Series[0].AddXY(random(100),random(100));
end;
tbChart.BottomAxis.SetMinMax(tbChart.Series[0].MinXValue*0.95,tbChart.Series[0].MaxXValue*1.05);
tbChart.LeftAxis.SetMinMax(tbChart.Series[0].MinYValue*0.95,tbChart.Series[0].MaxYValue*1.05);
end
else
begin
tbChart.Title.Text.Text:='电池数据分布图';
tbChart.Color := clWhite;
// 修改图表部分的背景色可以通过BackColor属性来实现:
tbChart.BackColor := clGreen;
// 此外,TChart还提供了渐变的背景支持,通过Gradient控制:
tbChart.Gradient.Visible := True;
tbChart.Gradient.Direction := gdFromTopLeft;
tbChart.Gradient.StartColor := clYellow;
tbChart.Gradient.EndColor := clGreen;
tbChart.Series[0].Clear;
for i:=0 to 8 do
begin
tbChart.Series[0].AddXY(random(100),random(100));
end;
tbChart.BottomAxis.SetMinMax(tbChart.Series[0].MinXValue*0.95,tbChart.Series[0].MaxXValue*1.05);
tbChart.LeftAxis.SetMinMax(tbChart.Series[0].MinYValue*0.95,tbChart.Series[0].MaxYValue*1.05);
end;
myvar:=myvar+1;
except
on e:exception do
begin
Application.MessageBox(PAnsiChar(e.Message),PAnsiChar(e.Message));
end;
end;
end;
效果:
本文介绍了一种使用Delphi中的TChart组件动态绘制电池数据分布图的方法。通过修改图表背景色及启用渐变效果增强图表视觉表现力,并利用随机数填充数据点。同时实现了根据变量值改变图表渐变颜色方向的功能。
&spm=1001.2101.3001.5002&articleId=51017475&d=1&t=3&u=1ba790aef2504d02942fadc6f5ccf4e0)
1239

被折叠的 条评论
为什么被折叠?



