Page 1 of 1
Synchronize Value
Posted: Tue May 11, 2004 2:57 pm
by 8575295
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 ??
Posted: Tue May 11, 2004 3:44 pm
by Pep
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) :
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.
Posted: Tue May 11, 2004 7:09 pm
by 8575295
My english is very Bad (speak french)
I try explain again.
I hope Obtain all value of the all series for
one value X (reference) , without click on chart but
with Serie[x].Xvalue
ex: for each Xvalue of the serie 1, how what Yvalue to correspond for all series ??
Posted: Wed May 12, 2004 2:50 pm
by Marjan
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.
Posted: Wed May 12, 2004 4:48 pm
by 8575295
Ok this the good response,
do have a code Delphi with example, please
for the speed practice.
And if in chart ago a TGanttSeries, i hope retreive
0 or 1 as value ???
And if in chart ago a TLineSeries, i hope retreive
Y value
Please, i don't all anderstand with linear function