Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,
I have this code that I show information of data chart with mouse move, but the thing is after the information is visible then it won't go away, so the more I move my mouse in the points the more mess gets my chart.

This is my code for showing information:


<pre>Private Sub Chart1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Chart1.MouseMove
        Dim result As HitTestResult = Chart1.HitTest(e.X, e.Y)
        If result.ChartElementType = ChartElementType.DataPoint Then
            ' Get getails from DataPoint.
            Dim department As String = result.Series.Name
            Dim Year As String = result.Series.Points(result.PointIndex).AxisLabel
            ' Dim NOA As String = result.Series.Points(result.PointIndex).AxisLabel
            Dim Total As Double = result.Series.Points(result.PointIndex).YValues(0)
            Dim thisPt As PointF = New PointF(Convert.ToSingle(result.Series.Points(result.PointIndex).XValue),
                                              Convert.ToSingle(result.Series.Points(result.PointIndex).YValues(0)))
            Dim ca As CalloutAnnotation = New CalloutAnnotation With {
                .AnchorDataPoint = result.Series.Points(result.PointIndex),
                .X = thisPt.X + 1,
                .Y = thisPt.Y + 1,
                .CalloutStyle = CalloutStyle.SimpleLine,
                .ForeColor = Color.Coral,
                .Font = New Font("Tahoma", 9, FontStyle.Bold),
                .Name = department,
                .Text = Year & " - " & department & Total
            }
            Chart1.Annotations(department) = ca
            Chart1.Invalidate()


        End If

    End Sub


What I have tried:

I google and there were some examples but nothing that I could work on.


Thank you, everyone,
Best regards
Posted
Updated 31-Jul-20 7:12am
Comments
[no name] 31-Jul-20 13:04pm    
Maybe a "tool tip" would work better ... they're designed for that purpose.

1 solution

I just had to use this line of code in front of the rest and it fix it.

Chart1.Annotations.Clear()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900