Nearestpoint tool - accessing the nearest point properties

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
seanmurphy
Newbie
Newbie
Posts: 48
Joined: Fri Mar 12, 2004 5:00 am

Nearestpoint tool - accessing the nearest point properties

Post by seanmurphy » Sun Oct 30, 2005 11:15 am

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Nov 02, 2005 9:11 am

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;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

seanmurphy
Newbie
Newbie
Posts: 48
Joined: Fri Mar 12, 2004 5:00 am

Post by seanmurphy » Wed Nov 02, 2005 11:35 am

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

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Nov 07, 2005 8:23 am

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;

Post Reply