OnClick coordinates

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
philip
Newbie
Newbie
Posts: 15
Joined: Tue Jun 26, 2007 12:00 am

OnClick coordinates

Post by philip » Sun Feb 20, 2011 5:53 pm

First - apologies for what is probably a dumb question. So thanks in advance for your help on the forum.
Second - in C++/VCL how do I determine the axis-based coordinates of a mouse click in a chart? That's to say, not the cursor coordinates on the Chart object itself (which start at 0,0 top-left) but within the displayed graph (with currently visible axes ranges)?

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: OnClick coordinates

Post by Yeray » Tue Feb 22, 2011 2:27 pm

Hi philip,

You can translate the coordinates in pixels taken, for example, from OnMouseDown event to coordinates in the axes units with CalcPosPoint function:

Code: Select all

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var XPos, YPos: Double;
begin
  XPos:=Chart1.Axes.Bottom.CalcPosPoint(X);
  YPos:=Chart1.Axes.Left.CalcPosPoint(Y);
  Chart1.Title.Text.Text:='X: ' + FormatFloat('#0.00', XPos) + ', Y: ' + FormatFloat('#0.00', YPos);
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

philip
Newbie
Newbie
Posts: 15
Joined: Tue Jun 26, 2007 12:00 am

Re: OnClick coordinates

Post by philip » Tue Feb 22, 2011 4:07 pm

Code: Select all

  XPos:=Chart1.Axes.Bottom.CalcPosPoint(X);
  YPos:=Chart1.Axes.Left.CalcPosPoint(Y);
perfect. many thanks

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: OnClick coordinates

Post by Yeray » Tue Feb 22, 2011 5:10 pm

You're welcome, Philip!
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply