Chart with four points while only two points was appeared (problem is vb.net Code)

Hany Metry 41 Reputation points
2023-11-29T12:11:15.3666667+00:00

Hi

There are an error in the code which make only 2 points are appear in the chart while when radiobutton3.checked = true or radiobutton4.checked= true, there must 4 points appear. Please advise the error in the code.


Public Class MyAnno
        Public SeriesFindex As Integer
        Public MTindex As string
End Class

Private Sub Form10Chart_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim MyAnnos As New List(Of MyAnno)

Me.Chart1.Annotations.Clear() If Form2GeneralInformation.RadioButton3.Checked = True Or Form2GeneralInformation.RadioButton4.Checked = True Then

Dim USS(3) As Double

USS(0) = Math.Abs(ut * 1000000)

USS(1) = Math.Abs(ub * 1000000)

USS(2) = Math.Abs(ut * 1000000 * 1.5)

USS(3) = Math.Abs(ub * 1000000 * 1.5)

For Kmz As Integer = 0 To 3

Me.Chart1.Series("Interaction Diagram8").Points.AddXY(DF, USS(Kmz))

Dim ma As New MyAnno

ma.SeriesFindex = Chart1.Series("Interaction Diagram8").Points.Count - 1

If Kmz = 0 Then

ma.MTindex = "ut"

ElseIf Kmz = 1 Then

ma.MTindex = "ub"

ElseIf Kmz = 2 Then

ma.MTindex = "ut x 1.5"

ElseIf Kmz = 3 Then

ma.MTindex = "ub x 1.5"

End If

MyAnnos.Add(ma)

Next

For Findex As Integer = 0 To MyAnnos.Count - 1

Dim PC As New TextAnnotation

With PC

.ForeColor = Color.Red

.Font = New Font("Tahoma", 10)

.AnchorDataPoint = Chart1.Series("Interaction Diagram8").Points(MyAnnos(Findex).SeriesFindex)

.X = Chart1.Series("Interaction Diagram8").Points(MyAnnos(Findex).SeriesFindex).XValue

.Y = Chart1.Series("Interaction Diagram8").Points(MyAnnos(Findex).SeriesFindex).YValues(0) .Text = MyAnnos(Findex).MTindex.ToString '& " " & PC.AnchorDataPoint.ToString

Chart1.Annotations.Add(PC)

End With

Next

End If

Chart1.refresh

end subAnnotation and points not drawn

Developer technologies | VB
Developer technologies | Visual Studio | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Hany Metry 41 Reputation points
    2023-11-29T15:06:25.1766667+00:00

    Hi Les,

    Attached as require - the total code is a project which can not put in the question

    Attached part of the code which show the problem

    Form10Chart is Form containing chart

    DIm ut as double = 0.00005

    Dim as double ub = 0.00007

    Public Class Form10Chart
     Public Class MyAnno         Public SeriesFindex As Integer         Public MTindex As string     End Class
    
    
    Private Sub Form10Chart_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim MyAnnos As New List(Of MyAnno)             
    Me.Chart1.Annotations.Clear()
    Dim USS(3) As Double                 USS(0) = Math.Abs(ut * 1000000)                 USS(1) = Math.Abs(ub * 1000000)                 USS(2) = Math.Abs(ut * 1000000 * 1.5)                 USS(3) = Math.Abs(ub * 1000000 * 1.5)                 For Kmz As Integer = 0 To 3                     Me.Chart1.Series("Interaction Diagram8").Points.AddXY(DF, USS(Kmz))                     Dim ma As New MyAnno                     ma.SeriesFindex = Chart1.Series("Interaction Diagram8").Points.Count - 1                     If Kmz = 0 Then                         ma.MTindex = "ut"                     ElseIf Kmz = 1 Then                         ma.MTindex = "ub"                     ElseIf Kmz = 2 Then                         ma.MTindex = "ut x 1.5"                     ElseIf Kmz = 3 Then                         ma.MTindex = "ub x 1.5"                     End If                     MyAnnos.Add(ma)                 Next                 For Findex As Integer = 0 To MyAnnos.Count - 1                     Dim PC As New TextAnnotation                     With PC                         .ForeColor = Color.Red                         .Font = New Font("Tahoma", 10)                         .AnchorDataPoint = Chart1.Series("Interaction Diagram8").Points(MyAnnos(Findex).SeriesFindex)                         .X = Chart1.Series("Interaction Diagram8").Points(MyAnnos(Findex).SeriesFindex).XValue                         .Y = Chart1.Series("Interaction Diagram8").Points(MyAnnos(Findex).SeriesFindex).YValues(0)                         .Text = MyAnnos(Findex).MTindex.ToString '& " " & PC.AnchorDataPoint.ToString                         Chart1.Annotations.Add(PC)                     End With                 Next                     Me.Chart1.Refresh()
    End Sub
    End Class
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.