Dynamic month change Axislabels on Chart VB.NET

111 views Asked by At

Im trying change every month the labels of the chart the correct order must be the oldest month to the newest (Ago, Sep, Oct, Nov, Dic, Jan) but when the instruction For Each mes As String In meses Chart1.Series(0).Points(n).AxisLabel = meses(n) n += 1 is reached the order changes to the one show in the image

Chart1

this is my code so far.

    Dim meses(6) As String ' = {"Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"}
    Dim Hoy As Date = DateTime.Now()
    Dim ScopeHoy As Date = Hoy.AddMonths(-6)
    Dim n As Integer = 0
    While (ScopeHoy <= Hoy)
        meses(n) = MonthName(ScopeHoy.Month, True)
        ScopeHoy = ScopeHoy.AddMonths(1)
        n += 1
    End While

    n = 0
    For Each mes As String In meses
        Chart1.Series(0).Points(n).AxisLabel = meses(n)
        n += 1
    Next

    'Asignar un valor de X a cada Mes
    n = 0
    While n < 6
        Chart1.Series(0).Points(n).XValue = n + 1
        n += 1
    End While

    'Sacar contadores para Llenar Chart
    Dim cM(11) As Integer
    For Each Renglon As DataGridViewRow In ListaDataGridHOLDS.Rows
        'If (Renglon.Cells("FInicial").Value > ) Then

        Select Case CDate(Renglon.Cells("FInicial").Value).Month
            Case 1
                cM(0) = cM(0) + 1
            Case 2
                cM(1) = cM(1) + 1
            Case 3
                cM(2) = cM(2) + 1
            Case 4
                cM(3) = cM(3) + 1
            Case 5
                cM(4) = cM(4) + 1
            Case 6
                cM(5) = cM(5) + 1
        End Select
    Next
    'Valores para pruebas
    'cM(0) = Int((Rnd() * 20) + 1)
    'cM(1) = Int((Rnd() * 5) + 1)
    'cM(2) = Int((Rnd() * 5) + 1)
    'cM(3) = Int((Rnd() * 20) + 1)
    'cM(4) = Int((Rnd() * 20) + 1)
    'cM(5) = Int((Rnd() * 5) + 1)
    'cM(6) = Int((Rnd() * 5) + 1)
    'cM(7) = Int((Rnd() * 5) + 1)
    'cM(8) = Int((Rnd() * 5) + 1)
    'cM(9) = Int((Rnd() * 5) + 1)
    'cM(10) = Int((Rnd() * 5) + 1)
    'cM(11) = Int((Rnd() * 5) + 1)

    'Asignar la cantidad de días a Y
    n = 0
    While n < 6
        Chart1.Series(0).Points(n).YValues(0) = cM(n)
        n += 1
    End While
0

There are 0 answers