Page 1 of 1

Nearestpoint tool - accessing the nearest point properties

Posted: Sun Oct 30, 2005 11:15 am
by 9231397
I have a chart with nearest point tool and lineserie. I'd like to get at information about the X,Y values of the actual point in the lineseries pointed at by the tool Something like...

procedure TMainForm.ChartTool1Change(Sender: TObject);
var
x:real;
begin
x:=sender.XValue[valueindex];
statusbar.panels[1].text:=floattostrf(x,fffixed,9,1);
end;

So as user moves the mouse the statusbar updates with x/y values.
The sender.xvalue[valueindex] above are what I use in the onclick event for Tlineseries. I can figure out which series the nearesttool is pointing at, but I'm not sure how to find which xvallue and yvalue the nearesttool is pointing at. Have read tutorials and forum, but still struggling. Any advice much appreciated.

thanks
Sean

Posted: Wed Nov 02, 2005 9:11 am
by narcis
Hi Sean,

If you figured out which series point the tool is pointing at then you just have to retrieve the X and Y Values from the series doing something like what's done here:

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var Index: Integer;
begin
  Index:=Series1.Clicked(X,Y);
  if Index<>-1 then
    Chart1.Title.Text[0]:=FloatToStr(Series1.XValue[Index])+', '+
                          FloatToStr(Series1.YValue[Index]);
end;

Posted: Wed Nov 02, 2005 11:35 am
by 9231397
thanks Narcis,

the bit I'm having trouble with is figuring out which series point the tool is pointing at. I expected (hoped) to find an X, Y in the toolchange event, but there wasn't. As I know which series the tool points at, is there not some sort of 'active point' in the series?

cheers
Sean

Posted: Mon Nov 07, 2005 8:23 am
by Pep
Hi Sean,

to do this you could use the following code :

Code: Select all

procedure TForm1.ChartTool1Change(Sender: TObject);
begin
if ChartTool1.Point <> -1 then
 Label1.Caption := 'Point index = ' + IntToStr(ChartTool1.Point) +
  '  X : '+ FloatToStr(Series1.XValue[Charttool1.Point]) + '   Y : '+ FloatToStr(Series1.YValue[Charttool1.Point])
else Label1.Caption := '';
end;