TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
Calou
- Advanced
- Posts: 104
- Joined: Wed Nov 19, 2008 12:00 am
Post
by Calou » Fri Dec 11, 2009 10:28 am
Hello,
I use TcursorTool like it :
Code: Select all
Procedure Tform1.CursorSynchronize( Source, Dest: TCursorTool );
begin
Dest.ParentChart.AutoRepaint:=False; // stop repainting
Dest.RedrawCursor; // hide cursor
Dest.XValue := Source.XValue;
Dest.RedrawCursor; // draw cursor again
Dest.ParentChart.AutoRepaint:=True; // enable repainting
end;
procedure TForm1.FormShow(Sender: TObject);
var
i:integer;
begin
for i := 0 to 10do
Series1.AddXY(i,i+1);
for i := 80 to 100 do
Series1.AddXY(i,i+1);
for i := 0 to 100do
Series2.AddXY(i,i+1);
end;
procedure TForm1.ChartTool1SnapChange(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
CursorSynchronize(sender,ChartTool1);
label1.Caption:='Y1='+FormatFloat('0.00',Series1.YValue[ValueIndex]);
label2.Caption:='X1='+FloatToStr(XValue);
label3.Caption:='Y2='+FormatFloat('0.00',Series2.YValue[ValueIndex]);
label4.Caption:='X2='+FloatToStr(XValue);
end;
the problem is that there is not the same number of points between Series1 and Series2. How can i do to have the Series1 Yvalue correct with its Xvalue?
I use ValueIndex but it is not correct in this case. I precise that there is no reason to print the Yvalue of Series1 if its Xvalue doesn't exist
Thanks for help
Regards
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Fri Dec 11, 2009 12:44 pm
Hi Calou,
You could use the Locate function to retrieve the ValueIndex in a series for a given X or Y value:
Code: Select all
procedure TForm1.ChartTool1SnapChange(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
var tmpIndex: Integer;
begin
CursorSynchronize(sender,ChartTool1);
tmpIndex:=Series1.XValues.Locate(XValue);
if (tmpIndex <> -1) then
label1.Caption:='Y1='+FormatFloat('0.00',Series1.YValue[tmpIndex])
else
label1.Caption:='Y1=Not present';
label2.Caption:='X1='+FloatToStr(XValue);
label3.Caption:='Y2='+FormatFloat('0.00',Series2.YValue[ValueIndex]);
label4.Caption:='X2='+FloatToStr(XValue);
end;
-
Calou
- Advanced
- Posts: 104
- Joined: Wed Nov 19, 2008 12:00 am
Post
by Calou » Fri Dec 11, 2009 3:47 pm