I have various points on a chart. I would like to be able to show the exact value of the point in a tooltip on mousing over that particular point.
Example:
Chart1.Series("Series1").Points.AddXY("Jul", 600)
Chart1.Series("Series1").Points.AddXY("aug", 458)
On mousing over these points on the chart, the tooltip text should show "600" or "458".
Edit:
This gets me close but it only shows the value of the mouse position on the point, not the full value of the point:
Private Sub Chart1_GetToolTipText(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs) Handles Chart1.GetToolTipText
If e.HitTestResult.PointIndex >= 0 Then
If e.HitTestResult.ChartElementType = DataVisualization.Charting.ChartElementType.DataPoint Then
MetroToolTip1.SetToolTip(Chart1, e.y.tostring)
End If
End If
End Sub
I realize you found a solution, but the simplest way is to set the 'Series.ToolTip' property.
Chart1.Series(0).ToolTip = "#VAL{0.0}"
The ToolTip makes use of keywords to define what value to display followed by an optional format specifier that follows the MS Custom Numeric Format Strings for the most part. The easiest way to find these keywords is to use the editor exposed in the PropertyGrid to set the ToolTip.
In this example the #VAL
tells it to display the y-value. The {0.0}
tells it to format the number using the "0.0" format string.
Edit: I found a table on the Dundas site (MS bought the control from them), that lists the Keywords and explains more about the format specifier usage. http://support2.dundas.com/Default.aspx?article=1132
Keywords documentation from MSDN: Keywords [rs_vsDataVis]
This is the code needed to show the point values:
Private Sub chart1_GetToolTipText(sender As Object, e As ToolTipEventArgs) Handles Chart1.GetToolTipText
' Check selected chart element and set tooltip text for it
Select Case e.HitTestResult.ChartElementType
Case ChartElementType.DataPoint
Dim dataPoint = e.HitTestResult.Series.Points(e.HitTestResult.PointIndex)
e.Text = dataPoint.YValues(0).ToString
Exit Select
End Select
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With