Delphi XE2 Graph慢

时间:2015-08-24 14:34:37

标签: delphi delphi-xe2 teechart

我正在创建一个Delphi应用程序,我希望在该应用程序中以图形方式显示数据。这些数据来自串口,所以我希望看到“实时”发生的事情。我注意到我的应用程序在一段时间后变得很慢。我认为这与更新图表有关。有人可以帮助我提高我的申请速度吗?出于测试目的,我做了这个测试应用程序,我每5毫秒得到一个随机数并将其添加到图表中,所以这不是我的最终应用程序,但效果是相同的。如果我尝试使用GetTickCount测量时间,我会看到“介于两者之间”的时间会增加。在我的最终应用程序中,我需要能够放置12个图表。有没有办法让它更快?

谢谢!

Source

单位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.

1 个答案:

答案 0 :(得分:1)

关于应用中的TeeChart使用和优化,我强烈建议您按照http://www.teechart.net/reference/articles/index.php

实时图表文章中的说明进行操作