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

I have different points on the graph. I would like to be able to show the exact value of a point in a tooltip about how the mouse is over that particular point.

Example:

Chart1.Series("Series1").Points.AddXY("Jul", 600)
Chart1.Series("Series1").Points.AddXY("aug", 458)

When moving along these points in the diagram, the tooltip text should show “600” or “458”.

Edit:

This brings me closer, but only shows the value of the mouse position at 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
+4
source share
2 answers

I understand that you have found a solution, but the easiest way is to set the Series.ToolTip property.

Chart1.Series(0).ToolTip = "#VAL{0.0}"

ToolTip , , , MS Custom Numeric Format Strings . - , PropertyGrid, .

#VAL y. {0.0} "0.0".

: Dundas (MS ), . http://support2.dundas.com/Default.aspx?article=1132

MSDN: [rs_vsDataVis]

+3

, :

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
0

Source: https://habr.com/ru/post/1652540/


All Articles