函數類型
函數特點
TeeChart Pro功能是一個系列,幾乎可以是任何系列類型,應用代數函數,數據源是另一個圖表系列。
所有函數都派生自TTeeFunction組件並繼承TeeFunction的Period屬性。
TeeChart Pro包含以下預定義功能列表。有關所有功能類型的完整列表,請參閱TeeChart Editor Gallery和Helpfile:
函數類別 | 導入數量 | 描述 |
Add | 無限 | 繪製輸入的總和 |
Average | 無限 | 平均函數將計算每組Period點的平均值 |
Bollinger | 1 | 布林線函數使用簡單或指數移動平均線來構建布林線交易區間 |
Copy | 1 | 輸入系列的直接副本 |
Curve Fitting | 1 | 使用TypeFitting公式通過數據輸入繪製擬合多項式 |
Divide | 無限 |
分割函數繪製輸入按包含的降序劃 |
Exponential Average | 1 | 基於權重的指數平均值 |
Exponential Moving Average | 1 | 基於權重的指數移動平均線 |
Exponential Trend | 1 | 通過輸入系列中的點繪製最佳指數趨勢 |
High | 無限 | 高功能繪製高輸入點 |
Low | 無限 | 低功能繪製低輸入點 |
MACD | 1 | 移動平均收斂分歧 |
Momentum | 1 | 每個Y值是當前點的Y值減去最後一個Period點的Y值 |
Momentum Division | 1 | 每個Y值是當前點的Y值除以最後一個Period點的YValue,以百分比表示 |
Moving Average | 1 | 移動平均線功能將計算每組週期點的簡單或加權平均值 |
Multiply | 無限 | 乘法函數繪製輸入值的乘積 |
Root Mean Square | 無限 | 均方根函數繪製輸入的RMS值 |
Relative Strength Index | 1 | RSI函數根據財務數據計算百分比值。根據TRSISyle類型,將使用不同的公式來計算RSI值 |
Standard Deviation | 1 | 映射每組Period點的標準偏差(或完全標準差) |
Stochastic | 1 | |
Subtract | 無限 | 繪圖的輸入值按包含的降序減去 |
Trend | 1 | 通過輸入系列點繪製最佳趨勢線 |
多種函數類型僅支持一個輸入系列。但是,可以鏈接鏈接函數,例如,將圖表中多個系列的平均值創建爲平均函數系列,然後使用平均函數作爲趨勢函數的輸入來標識平均值的趨勢。
添加函數
使用圖表編輯器,在“第一個圖表”頁面上,選擇“ 添加”按鈕,就像將新系列添加到圖表一樣。在TeeChart Gallery中,選擇Functions選項卡以選擇所需的功能。每個功能都顯示爲一個系列,您可以稍後通過選擇第一個圖表頁面上的更改按鈕來更改與該功能關聯的系列類型。之後,在函數系列的“數據源”頁面上可以輕鬆更改函數定義。在這裏,同樣容易,您可以將已添加到Chart的正常Series的定義更改爲Function的定義(Function實際上是數據源的定義,而不是Series Type的定義)。
下圖顯示了編輯函數時的“數據源”頁面。線系列(名稱“Series2”,標題“平均”)被定義。數據源頁面底部的左側列表框顯示了可用於輸入的圖表中的其他系列(此處爲“Series1”)。
假設我們從一個完全空的Chart開始,這裏是代碼中構建一個簡單的Series-Function相關Chart的步驟。
procedure TForm1.BitBtn5Click(Sender: TObject); var tmpBarSeries1, tmpBarSeries2 : TBarSeries; tmpLineSeries : TLineSeries; begin //Add 2 data Series tmpBarSeries1:=TBarSeries.Create(Self); tmpBarSeries2:=TBarSeries.Create(Self); AddSeries(tmpBarSeries1); AddSeries(tmpBarSeries2); //Populate them with data (here random) tmpBarSeries1.FillSampleValues(10); tmpBarSeries2.FillSampleValues(10); //Add a series to be used for an Average Function tmpLineSeries:=TLineSeries.Create(Self); AddSeries(tmpLineSeries); //Define the Function Type for the new Series tmpLineSeries.SetFunction(TAverageTeeFunction.Create(Self)); //Define the Datasource for the new Function Series //Datasource accepts the Series titles of the other 2 Series tmpLineSeries.DataSources.Clear; tmpLineSeries.DataSources.Add( tmpBarSeries1 ); tmpLineSeries.DataSources.Add( tmpBarSeries2 ); // *Note - When populating your input Series manually you will need to // use the Checkdatasource method // - See the section entitled 'Defining a Datasource' //Change the Period of the Function so that it groups averages //every 2 Points tmpLineSeries.FunctionType.Period := 2; end;
我們可以添加另一個函數來告訴我們有關前一個函數的信息
procedure TForm1.BitBtn6Click(Sender: TObject); var tmpHighLine : TLineSeries; begin //Add another Series to be used for a 2nd Function tmpHighLine:=TLineSeries.Create(Self); AddSeries(tmpHighLine); //Define the Function Type for the new Series tmpHighLine.SetFunction(THighTeeFunction.Create(self)); //Define the Datasource for the new Function Series //Use the existing Function (tmpLineSeries) as input //You should declare tmpLineSeries globally to the module //if you wish to use it between procedures tmpHighLine.DataSource := tmpLineSeries; //Leave the Period at default 0 (No Period set) to draw //A line at Highest of all points of the Average Function end;
定義數據源
上一節中的示例重點介紹了使用Datasource按代碼對函數進行內容處理。Series使用Datasource定義Function的輸入或定義Series TDataset數據源(請參閱有關訪問數據庫的教程)。
使用圖表編輯器,在添加函數後,函數系列的“數據源”頁面將顯示包含在函數定義中的可用系列列表。在這裏,您可以更改要應用於系列的功能類型,並從左側列表框“可用”中選擇系列,並將它們添加到右側列表框“已選擇”;。
按代碼的數據源使用Series.Datasource屬性。
假設我們在圖表中有2個數據系列。我們使用圖表編輯器添加由2系列的平均值組成的函數:
我們爲2系列添加點數:
var t : Integer; For t := 0 To 10 do begin Series1.Add(2 * t); Series2.Add(3 * t); end;
請注意,該功能不會顯示。您需要使用Series.CheckDatasource方法讀取Function的值。
Series3.CheckDataSource; //Read in data for Function
可以使用Setfunction方法在運行時更改函數定義,以便爲Series分配新函數。
Series3.Setfunction(TMovingAverageFunction.Create(self));
使用上面的代碼行,Setfunction將Series3的Function更改爲Moving Moving。
未完待續...
購買TeeChart Pro VCL/FMX正版授權,請點擊“諮詢在線客服”喲!