Page 1 of 1

TChart Editor

Posted: Tue Dec 28, 2010 5:14 pm
by 10052635
I would like to add a series at runtime that is a function of the series already run. The function would start with the second point of the first series with the X values being the same as the X values of the first series and the Y values computed as (X - Xprev)/(Y - Yprev) from the first series. Is this possible? Also, can the function itself be entered at runtime?

TChart Editor Functions

Posted: Tue Dec 28, 2010 5:49 pm
by 10052635
In relation to my last request, I am using Version 6 and would like to know if the standard functions for moving averages and exponential averages is available in V6?

Re: TChart Editor

Posted: Wed Dec 29, 2010 3:51 pm
by yeray
Hi Roy,
Roy wrote:I would like to add a series at runtime that is a function of the series already run. The function would start with the second point of the first series with the X values being the same as the X values of the first series and the Y values computed as (X - Xprev)/(Y - Yprev) from the first series. Is this possible? Also, can the function itself be entered at runtime?
Have you tried using the custom function? You could do something similar to following:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var source: TPointSeries;
    line: TLineSeries;
    func: TCustomTeeFunction;
begin
  Chart1.View3D:=false;

  source:=TPointSeries.Create(self);
  Chart1.AddSeries(source);
  source.FillSampleValues(100);

  line:=TLineSeries.Create(self);
  Chart1.AddSeries(line);
  func:=TCustomTeeFunction.Create(self);
  line.FunctionType:=func;
  func.NumPoints:=source.Count-1;
  func.StartX:=1;
  line.DataSource:=source;
  func.OnCalculate:=FunctionCalculate;
  func.ReCalculate;
end;

procedure TForm1.FunctionCalculate(Sender:TCustomTeeFunction; const x:Double; var y:Double);
var ValueIndex: Integer;
begin
  ValueIndex:=0;

  while ((ValueIndex <Chart1[0].Count) and (Chart1[0].XValue[ValueIndex] < x)) do
    Inc(ValueIndex);

  if ((ValueIndex>0) and (ValueIndex<Chart1[0].Count) and (Chart1[0].YValue[ValueIndex] <> Chart1[0].YValue[ValueIndex-1])) then
    y:=(Chart1[0].XValue[ValueIndex] - Chart1[0].XValue[ValueIndex-1]) / (Chart1[0].YValue[ValueIndex] - Chart1[0].YValue[ValueIndex-1]);
end;
Roy wrote:In relation to my last request, I am using Version 6 and would like to know if the standard functions for moving averages and exponential averages is available in V6?
Yes, I can see both functions in v6. You can see an example of all them in the features demo included with the installation:
- All features\Welcome !\Functions\Extended\Custom y=f(x)
- All features\Welcome !\Functions\Financial\Moving Average
- All features\Welcome !\Functions\Extended\Exp. Average