Hi,
Here's an example for using FindNearestPoint() that should give the general idea:
private void Form1_MouseDown( object sender, System.Windows.Forms.MouseEventArgs e )
{
CurveItem curve;
int iPt;
if ( myPane.FindNearestPoint( new PointF( e.X, e.Y ), out curve, out iPt ) )
MessageBox.Show( String.Format( "label = {0} X = {1}", curve.Label, curve.Points[iPt].ToString("e2") ) );
else
MessageBox.Show( "No Point Found" );
}
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Instead of a MessageBox, I'm trying to put a label. I got it to work correctly to show when there is no point found, but I can't figure out how to associate the coordinates of the point with a new label I am creating.
Code I am starting with, the "You did not click on a point" message works fine.
But the X value seems to be rounded or something. The Y is perfect, but all the labels appear on the same X lines (rounding?) instead of where the points are. Any idea?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is this a for a bar chart, where each bar within a cluster has the same X value? If so, you would need to user CurveItem.Bar.CalcBarCenter to get the actual pixel position of the bar. This is starting to get into the ZedGraph internal interface, which is probably best avoided since it will change from time to time.
Alternatively, you can use GraphPane.ReverseTransform to convert a mouse pt (from the mouse click) into a X,Y user coordinate. (even if you use CalcBarCenter, you would still need to use ReverseTransform to convert the pixel position to a user scale position).
If it's not a bar chart or if this isn't the problem, you can post your code in the support forum and I'll take a look at it.
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
First off, thank you for this library and the work you keep putting into it.
Is there any sample code on how to use FindNearestPoint ?
I have a date graph (stock quotes) and want to be able to click or hover for details.
Thank you.
Hi,
Here's an example for using FindNearestPoint() that should give the general idea:
private void Form1_MouseDown( object sender, System.Windows.Forms.MouseEventArgs e )
{
CurveItem curve;
int iPt;
if ( myPane.FindNearestPoint( new PointF( e.X, e.Y ), out curve, out iPt ) )
MessageBox.Show( String.Format( "label = {0} X = {1}", curve.Label, curve.Points[iPt].ToString("e2") ) );
else
MessageBox.Show( "No Point Found" );
}
John
Ok, I expanded this a bit but need a little help.
Instead of a MessageBox, I'm trying to put a label. I got it to work correctly to show when there is no point found, but I can't figure out how to associate the coordinates of the point with a new label I am creating.
Code I am starting with, the "You did not click on a point" message works fine.
Try this for the didFindCurve branch:
mousePosNoFound.Text = curve[iPt].ToString();
mousePosNoFound.X = curve[iPt].X;
mousePosNoFound.Y = curve[iPt].Y;
mousePosNoFound.CoordinateFrame = CoordType.AxisXYScale;
Invalidate();
You can add a little to the X or Y coordinate to offset the text from the data point (and also use AlignH & AlignV).
I previously mentioned the TextItem.Location class -- sorry to mislead you, that's actually in the new version (CVS).
John
Getting close!
I had to cast these:
But the X value seems to be rounded or something. The Y is perfect, but all the labels appear on the same X lines (rounding?) instead of where the points are. Any idea?
Is this a for a bar chart, where each bar within a cluster has the same X value? If so, you would need to user CurveItem.Bar.CalcBarCenter to get the actual pixel position of the bar. This is starting to get into the ZedGraph internal interface, which is probably best avoided since it will change from time to time.
Alternatively, you can use GraphPane.ReverseTransform to convert a mouse pt (from the mouse click) into a X,Y user coordinate. (even if you use CalcBarCenter, you would still need to use ReverseTransform to convert the pixel position to a user scale position).
If it's not a bar chart or if this isn't the problem, you can post your code in the support forum and I'll take a look at it.
John
Thank you, will give this a try.