How calculate YValue from other series??

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
MD
Newbie
Newbie
Posts: 15
Joined: Tue Jun 28, 2005 4:00 am
Location: France

How calculate YValue from other series??

Post by MD » Mon Sep 12, 2005 3:26 pm

Hi,

D7 and Teechart Pro Vcl 7.04

exemple sample , you have too serie
serie1 with
point 1 = 10:00 15.5
point 2 = 11:00 23.3
point 3= 12:00 27.0

and Serie 2 with
point 1 = 08:30 42
point 2 = 15:00 24

how take for the retreive graphic value from series 2 at each point serie 1

serie 1 serie 2
point 1 = 10:00 15.5 ?
point 2 = 11:00 23.3 ?
point 3= 12:00 27.0 ?



if you have a example or the best practice ??

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Sep 12, 2005 3:34 pm

Hi MD,

Assuming both series have the same number of points you can use the following code in the TChart's MouseMove event.

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  ValueIndex: Integer;
begin
  ValueIndex:=Series1.Clicked(X,Y);

  if (ValueIndex <> -1) then
    Chart1.Title.Text[0]:=FloatToStr(Series2.XValue[ValueIndex]) + ', ' +
                          FloatToStr(Series2.YValue[ValueIndex]);
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

MD
Newbie
Newbie
Posts: 15
Joined: Tue Jun 28, 2005 4:00 am
Location: France

Post by MD » Mon Sep 12, 2005 5:18 pm

hi

tank,

But not same number of point in each séries, this is difficult in my PB

I find the kind linear or extrapolation solution !!!!

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Sep 13, 2005 10:29 am

Hi MD,

Then interpolating the series is necessary. You can do something like the code below. I'm also going to post the full project at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.

Code: Select all

function TForm1.InterpolateLineSeries(Series: TChartSeries; FirstIndex,
                                   LastIndex: Integer; XValue: Double): Double;
var
  Index: Integer;
  dx,dy: Double;
begin
  for Index:=FirstIndex to LastIndex do
    if Series.XValues.Value[Index]>XValue then break;

  //safeguard
  if (Index<1) then Index:=1
  else if (Index>=Series.Count) then Index:=Series.Count-1;

  // y=(y2-y1)/(x2-x1)*(x-x1)+y1
  dx:=Series.XValues.Value[Index] - Series.XValues.Value[Index-1];
  dy:=Series.YValues.Value[Index] - Series.YValues.Value[Index-1];

  if (dx<>0) then
    result:=dy*(XValue - Series.XValues.Value[Index-1])/dx + Series.YValues.Value[Index-1]
  else result:=0;
end;

function TForm1.InterpolateLineSeries(Series: TChartSeries;XValue: Double): Double;
begin
  result:=InterpolateLineSeries(Series,Series.FirstDisplayedIndex,Series.LastValueIndex,XValue);
end;


procedure TForm1.ChartTool1Change(Sender: TCursorTool; x, y: Integer;
  const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
var
  i: Integer;
begin
  With Chart1.Title.Text do
  begin
    Clear;
    for i:=0 to Chart1.SeriesCount - 1 do
        Add(Chart1[i].Name + ': Y('+FloatToStr(XValue)+')= ' +
            FloatToStr(InterpolateLineSeries(Chart1[i],XValue))+#13#10);
  end;
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

MD
Newbie
Newbie
Posts: 15
Joined: Tue Jun 28, 2005 4:00 am
Location: France

Post by MD » Tue Sep 13, 2005 7:46 pm

Ok, i found this good example who function with
same number of point in each series.

But how take with not same number of point ???

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Sep 14, 2005 9:44 am

Hi MD,

It works fine for me here using different number of points for each series, try populating your series doing something like:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i:=0 to Chart1.SeriesCount - 1 do Chart1[i].FillSampleValues(10+1*i);
end;
Then the code I posted will interpolate each series value according to the current TCursorTool position and will display the interpolation on TChart's title.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

MD
Newbie
Newbie
Posts: 15
Joined: Tue Jun 28, 2005 4:00 am
Location: France

Post by MD » Wed Sep 14, 2005 5:23 pm

Ok tank

this functionne with other points, but the good formule
is // y=((y2-y1)*(x-x1)) / (x2-x1) +y1

not // y=(y2-y1)/(x2-x1)*(x-x1)+y1

bye

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Sep 15, 2005 7:12 am

Hi MD,

this is what is actually calculated:

Code: Select all

result:=dy*(XValue - Series.XValues.Value[Index-1])/dx + Series.YValues.Value[Index-1]
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply