Functions

A function may be defined to use one of most Series types as a ‘carrier’ Series and to act upon other Series to create its source data. When the function is defined it behaves as any other Series. Functions may thus be built upon other functions. Only in its definition of data source is a function different from other Series as it contains information that relates it statistically to other data sources by formula, sum, etc.

Topics in this Section:

Adding a function with the Chart editor

Deleting a function with the Chart editor

Changing a FunctionType with the Chart editor

Adding a function by code

Deleting a function by code

Period

Adding a function with the Chart editor

Functions may be added using the Chart editor at design time. Similarly to adding a Series you may use the TeeChart Gallery to choose the function. In the Gallery all functions are initially displayed as LineSeries functions - you may change Series type after initially adding the function.

When you have added the function go to the DataSource tab of the Series page. Here you may choose which input Series (or Series) to add to the function. The first Series in the selected listbox, reading from top to bottom, is the Series on which the operation is performed in the case of function which doesn’t treat each member of the list homogeneously.

Eg. Subtract.

Width1Width3Width1418Width3Width5883Fig. 1.

Subtract function defined in the Chart editor

Width1Width3Width1418Width3Width5883

  Width1Width3Width1418Width3Width5883

In the Chart editor screen you see Series3 being defined with inputs Series1 and Series2. The Series order in the list defines which Series is doing the subtraction.

Here:Series3:= Series1 - Series2

Deleting a function with the Chart editor

Alternatively you may delete the Series you have added as carrier for the function (delete Series from the first page of the Chart editor) or you may redefine the Series as having a different datasource in the DataSource tab of the Series page.

Changing a FunctionType with the Chart editor

The option to change the FunctionType is in the DataSource tab of the Series page for the function Series. The drop down combobox contains a list of all function types - You may choose any from the list. Copy will directly copy the input Series (duplicating the Series).

Adding a function by code

Function is a component. When you add a new function you are adding a Series, defining a new function and setting it as FunctionType for the Series.

Series1.SetFunction(TAddTeeFunction.Create(Self));

See the online help for a description of how to add each of the different types of function. Each function uses the same Series method, SetFunction.

Deleting a function by code

To delete a function from a Series either delete the Series or use the SetFunction method to de-allocate the connection between the Series and the Function.

Series1.SetFunction(nil);

Period

You may find the Period property extremely useful when working with functions. It is used to define the frequency for which the function re-calculates.

Example

We have 6 data points (eg. bars of a Bar Series) with values:

3, 8, 6, 2, 9 and 12

We define a function Series with Period 0 (default when only one Series is input to the Function) the average drawn is:

6.667

With Period set to 2 we get 3 values of average as output from the function:

5.5, 4 and 10.5

These values will plot centrally in their period range, ie. The 1st value between bars 1 and 2 of the input Series, 2nd value between bars 3 and 4, etc..

You may define Period by selecting the function in the Object Inspector or you may modify Period at runtime using FunctionType.

Eg. Where Series 2 is the function Series:

Series2.FunctionType.Period:=2