[Solved] Chart Series Name returns null on MouseMove event in Windows Application

Last Reply 7 months ago By dharmendr

Posted 7 months ago

Hello Everyone,

I am doing a project in Vb.net and I want to show information in my data chart when the mouse rolls over the chart, I don't have any proper error since my app does not stop functioning but when I use stop point and I go step by step I have this error that shows in :

Dim department As String = result.Series.Name
Dim Year As String = result.Series.Points(result.PointIndex).AxisLabel
Dim total As Double = result.Series.Points(result.PointIndex).YValues(0)

in the department as results, it gives = Nothing and then

in Year and in Total if I go to SERIES it says NOTHING and if I go to Points it gives me this: systemNullREferenceException.

And that is all but it won't stop my app. 

This is the whole code -- 

Private Sub Chartday_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Chartday.MouseMove
      Dim pos = e.Location
      If prevPosition.HasValue AndAlso pos = prevPosition.Value Then Return
      tooltip.RemoveAll()
      prevPosition = pos
      Dim results = Chartday.HitTest(pos.X, pos.Y, False, ChartElementType.DataPoint)
      For Each result In results
          If result.ChartElementType = ChartElementType.DataPoint Then
              Dim department As String = result.Series.Name
              Dim Year As String = result.Series.Points(result.PointIndex).AxisLabel
              Dim total As Double = result.Series.Points(result.PointIndex).YValues(0)
              Dim yVal = result.ChartArea.AxisY.PixelPositionToValue(pos.Y)
              tooltip.BackColor = Color.LightGray
              tooltip.ToolTipTitle = "Data Information"
              tooltip.Show(GetDetails(Year, department), Chartday, pos.X, pos.Y - 15)
          End If
      Next
  End Sub

Any help is much appriciated.

This question does not have replies that have been liked.