原創|使用教程|編輯:郝浩|2013-04-28 13:20:33.000|閱讀 732 次
概述:本教程就為大家提供幾種,老牌圖表控件TeeChart Pro VCL可以確保數據繪制速度的方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
所謂實時數據圖,就是圖表中的數據與圖表的生成為同一瞬間。當然這是非常理想化的,在現實中,只有提高繪圖速度,盡可能減少測量和繪制數據之間的延遲,本教程就為大家提供幾種,老牌圖表控件TeeChart Pro VCL可以確保數據繪制速度的方法。
以下方法都可以加快繪制實時數據圖的時間:
由于預處理數據的方式太多,而且在其他地方也有很深入的介紹,我們在這里不做介紹了。
直接進入填充數據系列,最簡單的方法就是使用AddXY方法來為系列增加數據點。這種方法的一大優點是,它非常簡單。如果你需要實時繪制的數據點數不超過幾千個,那么AddXY方法絕對是你的首選方法。
還有一個是TChartSeries.Delete方法,也提供了強大的實時繪制方法。接下來我們用兩個例子來展示使用TeeChart實際案例中的一個實時滾動圖表。
首先例行增加一系列的數據點,然后滾動的添加新數據點并刪除舊的且不必要的數據點,如下代碼:
  // Adds a new random point to Series
  Procedure RealTimeAdd(Series:TChartSeries);
  var XValue,YValue : Double;
  begin
    if Series.Count=0 then  // First random point
    begin
      YValue:=Random(10000);
      XValue:=1;
    end
    else
    begin
      // Next random point
      YValue:=Series.YValues.Last+Random(10)-4.5;
      XValue:=Series.XValues.Last+1;
    end;
    // Add new point
    Series.AddXY(XValue,YValue);
  end;
  // When the chart is filled with points, this procedure
  // deletes and scrolls points to the left.
  Procedure DoScrollPoints(Series: TChartSeries);
  var tmp,tmpMin,tmpMax : Double;
  begin
    // Delete multiple points with a single call.
    // Much faster than deleting points using a loop.
    Series.Delete(0,ScrollPoints);
    // Scroll horizontal bottom axis
    tmp := Series.XValues.Last;
    Series.GetHorizAxis..SetMinMax(tmp-MaxPoints+ScrollPoints,tmp+ScrollPoints);
    // Scroll vertical left axis
    tmpMin := Series.YValues.MinValue;
    tmpMax = Series.YValues.MaxValue;
    Series.GetVertAxis.SetMinMax(tmpMin-tmpMin/5,tmpMax+tmpMax/5);
    // Do chart repaint after deleting and scrolling
    Application.ProcessMessages;
  end;
另外一個支持增加大量數據點的方法是直接使用動態數組。下面這個例子就是這樣,我們繞過了AddXY方法,直接訪問系列X,Y的值,從而避免了使用AddXY方法的性能開銷。
Var X,Y : Array of Double;   // TChartValues
    t   : Integer;
    Num : Integer;
begin
  { 1M points }
  Num:= 1000000;
  { allocate our custom arrays }
  SetLength(X,Num);
  SetLength(Y,Num);
  { fill data in our custom arrays }
  X[0]:=0;
  Y[0]:=Random(10000);
  for t:=1 to Num-1 do
  begin
    X[t]:=t;
    Y[t]:=Y[t-1]+Random(101)-50;
  end;
  { set our X array }
  With Series1.XValues do
  begin
    Value:=TChartValues(X);  { <-- the array }
    Count:=Num;               { <-- number of points }
    Modified:=True;           { <-- recalculate min and max }
  end;
  { set our Y array }
  With Series1.YValues do
  begin
    Value:=TChartValues(Y);
    Count:=Num;
    Modified:=True;
  end;
  { Show data }
  Series1.Repaint;
上面這個例子中,有一個需要注意的地方,我們需要手動定義XValues.Count和YValues.Count的屬性。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:慧都控件網