我正在制作一个Delphi应用程序,我想在图形中显示数据。这些数据来自串行端口,所以我想看到"实时"发生了什么。我注意到我的应用程序在一段时间后变得很慢。我认为这与更新图像有关。有人能帮我使我的申请更快吗?出于测试目的,我制作了这个测试应用程序,其中我每5毫秒获得一个随机数并将其添加到图形中,因此这不是我的最终应用程序,但效果是相同的。如果我尝试用GetTickCount来测量时间,我看到In Between的时间增加了。在我最后的应用程序中,我需要能够放置12个图形。有没有办法让它快一点?
谢谢!
来源单元MainUnit;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, VCLTee.TeEngine,
VCLTee.Series, VCLTee.TeeProcs, VCLTee.Chart, DateUtils, Vcl.StdCtrls,
Vcl.ComCtrls, Math;
type
TMainForm = class(TForm)
Chart01: TChart;
AreaSeries4: TAreaSeries;
Panel1: TPanel;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
AddLabel: TLabel;
InBetweenLabel: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
AfterAddPoint: integer;
procedure FillChart(RealValue: real);
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
procedure TMainForm.FillChart(RealValue: real);
var Chart: TChart;
begin
Chart:=MainForm.Chart01;
Chart.Axes.Bottom.SetMinMax(IncMinute(Now, -20), Now); //Moet hier staan, anders worden grafieken niet live geupdate
Chart.Series[0].AddXY(Now, RealValue, '' );
end;
{$R *.dfm}
procedure TMainForm.Timer1Timer(Sender: TObject);
var BeforeAddPoint, Diverence: integer;
begin
BeforeAddPoint:= GetTickCount;
Diverence:=BeforeAddPoint-AfterAddPoint;
InBetweenLabel.Caption:=IntToStr(Diverence);
FillChart(RandomRange(50,52));
AfterAddPoint:=GetTickCount;
Diverence:=AfterAddPoint-BeforeAddPoint;
AddLabel.Caption:=IntToStr(Diverence);
end;
end.
关于应用程序中TeeChart的使用和优化,我强烈建议您遵循http://www.teechart.net/reference/articles/index.php
实时图表文章中所解释的内容。