原創(chuàng)|使用教程|編輯:郝浩|2013-04-28 13:20:33.000|閱讀 721 次
概述:本教程就為大家提供幾種,老牌圖表控件TeeChart Pro VCL可以確保數(shù)據(jù)繪制速度的方法。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
所謂實(shí)時(shí)數(shù)據(jù)圖,就是圖表中的數(shù)據(jù)與圖表的生成為同一瞬間。當(dāng)然這是非常理想化的,在現(xiàn)實(shí)中,只有提高繪圖速度,盡可能減少測(cè)量和繪制數(shù)據(jù)之間的延遲,本教程就為大家提供幾種,老牌圖表控件TeeChart Pro VCL可以確保數(shù)據(jù)繪制速度的方法。
以下方法都可以加快繪制實(shí)時(shí)數(shù)據(jù)圖的時(shí)間:
由于預(yù)處理數(shù)據(jù)的方式太多,而且在其他地方也有很深入的介紹,我們?cè)谶@里不做介紹了。
直接進(jìn)入填充數(shù)據(jù)系列,最簡(jiǎn)單的方法就是使用AddXY方法來(lái)為系列增加數(shù)據(jù)點(diǎn)。這種方法的一大優(yōu)點(diǎn)是,它非常簡(jiǎn)單。如果你需要實(shí)時(shí)繪制的數(shù)據(jù)點(diǎn)數(shù)不超過(guò)幾千個(gè),那么AddXY方法絕對(duì)是你的首選方法。
還有一個(gè)是TChartSeries.Delete方法,也提供了強(qiáng)大的實(shí)時(shí)繪制方法。接下來(lái)我們用兩個(gè)例子來(lái)展示使用TeeChart實(shí)際案例中的一個(gè)實(shí)時(shí)滾動(dòng)圖表。
首先例行增加一系列的數(shù)據(jù)點(diǎn),然后滾動(dòng)的添加新數(shù)據(jù)點(diǎn)并刪除舊的且不必要的數(shù)據(jù)點(diǎn),如下代碼:
// 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;
另外一個(gè)支持增加大量數(shù)據(jù)點(diǎn)的方法是直接使用動(dòng)態(tài)數(shù)組。下面這個(gè)例子就是這樣,我們繞過(guò)了AddXY方法,直接訪問(wèn)系列X,Y的值,從而避免了使用AddXY方法的性能開(kāi)銷(xiāo)。
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;
上面這個(gè)例子中,有一個(gè)需要注意的地方,我們需要手動(dòng)定義XValues.Count和YValues.Count的屬性。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)