Get Graph Point value when cursor points it

Dear All,

I am developing a GUI which I use to display some values with a TGraph in a Canvas, and I want to retrieve these values (x,y) when I put the mouse pointer over a specific point. Then, display it using a status bar (although a tooltip may be possible too).
The problem I find is that I can only retrieve the pixel coordinates transformed to canvas coordinates of my pointer, but not the actual value stored in the TGraph I am pointing.
For a histogram I would know roughly how to do it. Just get X coordinate
using :

h->GetBinCenter(h-> FindBin(x))

I have taken a look at :
THistPainter:GetObjectInfo

And looked to a related one for TGraph…
Could you please educate me if there is a way to do it?
Thank you!

That should be equivalent (close) to the graph’s points ?

You could retrieve which point you are actually accessing analogously to this function:
root.cern.ch/doc/master/TGraphP … tml#l00597

Yes, it is close, as close as the precision of your hand , but there is some margin, so I was wondering if there exists a built-in method for it.
A workaround i guess, would be to loop for the closest TGraph point of every pixel, whenever a TGraph is pointed
I have found something similar at:
TGraphPainter::ExecuteEventHelper

case kMouseMotion:

middle = kTRUE;
for (i=0;i<theNpoints;i++) {
d   = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
if (d < kMaxDiff) middle = kFALSE;
}

The code ferhue pointed, is what we do in root to retrieve the graph’s points when you interactively play with on a canvas.

OK, thank you.
I will then use something similar then.

Regards

As you already have the X and U value close to the point, the simplest is surely to loop on the graph’s points and compare them with the X Y value you have within some error box.

Also, may be this can give ideas:

root.cern/doc/master/classTAttL … f99d81ec84

Thank you Couet and ferhue,
I managed to do it doing a search for the closest point.

Regards