TChart Editor

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Roy
Newbie
Newbie
Posts: 64
Joined: Wed Feb 25, 2009 12:00 am
Location: Dallas, Texas
Contact:

TChart Editor

Post by Roy » Tue Dec 28, 2010 5:14 pm

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?

Roy
Newbie
Newbie
Posts: 64
Joined: Wed Feb 25, 2009 12:00 am
Location: Dallas, Texas
Contact:

TChart Editor Functions

Post by Roy » Tue Dec 28, 2010 5:49 pm

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?

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TChart Editor

Post by Yeray » Wed Dec 29, 2010 3:51 pm

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
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply