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 ??
How calculate YValue from other series??
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi MD,
Assuming both series have the same number of points you can use the following code in the TChart's MouseMove event.
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 |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
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.
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 |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi MD,
It works fine for me here using different number of points for each series, try populating your series doing something like:
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.
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;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi MD,
this is what is actually calculated:
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 |
Instructions - How to post in this forum |