We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to display the X and Y values while doing MouseMove on the chart?

Platform: WinForms |
Control: Chart |
Published Date: April 30, 2011 |
Last Revised Date: June 25, 2019

 

You can display the X and Y values while doing any Mouse Events like MouseUp, MouseDown, MouseHover, MouseLeave on the chart by using the methods GetValueByPoint which returns the X and Y values of the ChartSeries calculated from the mousepoint and GetPointByValue which returns the X and Y values of the mousepoint calculated from the ChartPoint. Using tooltip we can display the above data. The following code snippet must be given under the Mouse Event handler

C#

private void chartControl1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)

{

//This gives the corresponding X and Y coordinates of the mouse point.

Point mousePoint = new Point( e.X, e.Y );

 //The GetValueByPoint method returns the X and Y values of the ChartSeries calculated from the mousepoint.

ChartPoint chpt = chartControl1.ChartArea.GetValueByPoint( new Point( e.X, e.Y ) );

 //The GetPointByValue method returns the X and Y values of the mousepoint calculated from the ChartPoint.

Point pt = chartControl1.ChartArea.GetPointByValue( chpt );

 string text = "Mouse point: " + mousePoint.ToString() + "\nResult of method GetValueByPoint: {" + chpt.X .ToString() + "," + chpt.YValues[0].ToString() + "}" + "\nResult of method GetPointByValue: " + pt.ToString();

 //As mouse moves over the chartcontrol this displays the values as ToolTip.

toolTip1.SetToolTip(this.chartControl1,text);

}

 

VB

Private Sub chartControl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ChartControl1.MouseMove

'This gives the corresponding X and Y coordinates of the mouse point.

Dim mousePoint As Point = New Point(e.X, e.Y)

'The GetValueByPoint method returns the X and Y values of the ChartSeries calculated from the mousepoint.

Dim chpt As ChartPoint = ChartControl1.ChartArea.GetValueByPoint(New Point(e.X, e.Y))

'The GetPointByValue method returns the X and Y values of the mousepoint calculated from the ChartPoint.

Dim pt As Point = ChartControl1.ChartArea.GetPointByValue(chpt)

Dim [text] As String = "Mouse point: " + mousePoint.ToString() + vbLf + "Result of method GetValueByPoint: {" + chpt.X.ToString() + "," + chpt.YValues(0).ToString() + "}" + vbLf + "Result of method GetPointByValue: " + pt.ToString()

'As mouse moves over the chartcontrol this displays the values as ToolTip.

ToolTip1.SetToolTip(Me.ChartControl1, text)

End Sub

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon