Zach Johnson Zach Johnson - 1 year ago 218 Question

How do you view the value of a chart point on mouse over?

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.


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".


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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download