TeeChart Pro VCL/FMX教程(七):使用函數(一)

下載TeeChart Pro VCL/FMX最新版本數據庫

函數類型

函數特色

    TeeChart Pro功能是一個系列,幾乎能夠是任何系列類型,應用代數函數,數據源是另外一個圖表系列。dom

    全部函數都派生自TTeeFunction組件並繼承TeeFunction的Period屬性。編輯器

    TeeChart Pro包含如下預約義功能列表。有關全部功能類型的完整列表,請參閱TeeChart Editor Gallery和Helpfile:ide

函數類別函數

導入數量

描述spa

Add 無限 繪製輸入的總和
Average 無限 平均函數將計算每組Period點的平均值
Bollinger 1 布林線函數使用簡單或指數移動平均線來構建布林線交易區間
Copy 1 輸入系列的直接副本
Curve Fitting 1 使用TypeFitting公式經過數據輸入繪製擬合多項式
Divide 無限

 

分割函數繪製輸入按包含的降序劃orm

Exponential Average 1 基於權重的指數平均值
Exponential Moving Average 1 基於權重的指數移動平均線
Exponential Trend 1

經過輸入系列中的點繪製最佳指數趨勢blog

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」)。

Teechart

假設咱們從一個徹底空的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。

未完待續...

相關文章
相關標籤/搜索