Hello
How know the other series values from the first serie with the same
reference X values ??
I hope obtain the synchronize value Y for one reference X
ex:
for i:=0 to Chart1.Series[0].Count-1 do begin
//retreive a X référence from fisrt serie
ValRefX:= Chart1.Series[0].Xvalue;
// calcul the position X
PosX := Chart1.Series[1].CalcXPosValue(ValRefX);
// try retreive value Y for other serie, but ????
Val1:= Chart1.Series[1].XScreenToValue(PosX);
Val2:= Chart1.Series[2].XScreenToValue(PosX);
etc but PB
How the good practice ??
Synchronize Value
Hi,
I'm not sure if I understand what are you looking for. In case you want to know the YValue at certain XPosition you can use similar code to the following example (which shows the YValue of the Series moving the Mouse over the Chart) :
I'm not sure if I understand what are you looking for. In case you want to know the YValue at certain XPosition you can use similar code to the following example (which shows the YValue of the Series moving the Mouse over the Chart) :
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues(100);
Series1.HorizAxis := aBothHorizAxis;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var i, s, posi : integer;
begin;
Chart1.Repaint;
Chart1.Canvas.Brush.Style := bsClear;
If Chart1.SeriesCount > 0 Then
begin
for s := 0 to Chart1.SeriesCount-1 do
begin
If Chart1.Series[s].Count > 0 Then begin
For i := Chart1.Axes.Top.PosAxis To Chart1.Axes.Bottom.PosAxis do begin
If Chart1.Series[s].Clicked(X, i) <> -1 Then posi := i;
end;
Chart1.Canvas.TextOut( 10, 10 + (10 * s), 'Series ' + inttostr(s) + ' Value: ' + floattostr(Chart1.Series[s].YScreenToValue(posi)));
end;
end;
end;
Chart1.Canvas.Pen.Color := clBlue;
Chart1.Canvas.MoveTo (X, Chart1.Axes.Top.PosAxis);
Chart1.Canvas.LineTo( X, Chart1.Axes.Bottom.PosAxis);
end;
end.
Pep Jorge
http://support.steema.com
http://support.steema.com
Hi.
If other series have the same x value in their valuelist, you can use the Locate method. However, usually this is not the case i.e. series x values are not the same. This somewhat (but not that much) complicates the y y value for specific x value.
In case you're using line series you can use linear interpolation formula to calculate predicted y value at specific x coordinate. To construct interpolation formula you'll need two closest points to the current x value. This can be done by cycling through all visible points and remembering the closest point indices. Now you have two points (P1(x1,y1) and P2(x2,y2) which define the linear approximation:
y(x)-y1=(y2-y1)/(x2-x1)*(x-x1)
Note: formula above is valid only for x=[x1,x2] range. Now you can use your x value to calculate y(x) for specific series.
If other series have the same x value in their valuelist, you can use the Locate method. However, usually this is not the case i.e. series x values are not the same. This somewhat (but not that much) complicates the y y value for specific x value.
In case you're using line series you can use linear interpolation formula to calculate predicted y value at specific x coordinate. To construct interpolation formula you'll need two closest points to the current x value. This can be done by cycling through all visible points and remembering the closest point indices. Now you have two points (P1(x1,y1) and P2(x2,y2) which define the linear approximation:
y(x)-y1=(y2-y1)/(x2-x1)*(x-x1)
Note: formula above is valid only for x=[x1,x2] range. Now you can use your x value to calculate y(x) for specific series.
Marjan Slatinek,
http://www.steema.com
http://www.steema.com