none
Display all bars on the (x) axis with values legend RRS feed

  • Question

  •   

    Group


    Personnel how to correctly display a graph with 10 bars and with all the legends of the bar (x)


        Private cySale () As Double = {85241, 35210, 24560, 18425, 15000, 12500,
                                   8630, 7520, 4200, 3400}


        Private cxFruits () As String = {"Pear", "Apple", "Guava", "Peach", "Watermelon"
                               "Banana", "Orange", "Khaki", "Melon", "Strawberry"}


    In the case of Chart 1, leaving Maximum with the value 10.

      grpGrafico4.ChartAreas (0) .AxisX.Maximum = 10

      And leaving off the line below is not displaying the last full bar of Fruit (Strawberry)
      And the last figure of 3400 is not showing up.

     'grpGrafico4.ChartAreas (0) .AxisX.Interval = 0.5




    In the case of Chart 2, leaving Maximum with the value 11.

      grpGrafico4.ChartAreas (0) .AxisX.Maximum = 11

      And leaving off the line below it displayed all, except it is not displaying all the names of the fruits.
      (example: Apple, Peach, Banana, Khaki, Strawberry
      Only all values ​​were displayed.

     'grpGrafico4.ChartAreas (0) .AxisX.Interval = 0.5




    In case of chart 3, leaving Maximum with the value 11.

      grpGrafico4.ChartAreas (0) .AxisX.Maximum = 11

      And letting the line activated below it displayed all, only that it is displaying the scales in 0.5 only that ai there exhibited all the names of the fruits and legends of the bar (x).
      You can not display the scale, but display all the fruits and legends of the bar (x).

     grpGrafico4.ChartAreas (0) .AxisX.Interval = 0.5

    chart 1

    chart 2

    chart 3

    Private Sub btnProcessar1_Click(sender As Object, e As EventArgs) Handles btnProcessar1.Click
    
            Try
                Dim s_cySale() As Double = {85241, 35210, 24560, 18425, 15000, 12500,
                                   8630, 7520, 4200, 3400}
    
    
                Dim s_cxFruits() As String = {"Pear", "Apple", "Guava", "Peach", "Watermelon ",
                               "Banana", "Orange", "Khaki", "Melon ", "Strawberry"}
    
                Me.grpGrafico4.Series.Clear()
                Me.grpGrafico4.Titles.Clear()
    
                grpGrafico4.Titles.Add("Top Selling (Fruit) - 10 Most Sold Fruits 2018")
    
                grpGrafico4.Titles(0).Font = New Font("Times New Roman", 18, FontStyle.Bold)
                grpGrafico4.Titles(0).ForeColor = Color.Pink
    
                grpGrafico4.AntiAliasing = Charting.AntiAliasingStyles.All
                grpGrafico4.TextAntiAliasingQuality = Charting.TextAntiAliasingQuality.High
    
                grpGrafico4.Palette = Charting.ChartColorPalette.Chocolate
    
                Dim xseries As Charting.Series = New Charting.Series
    
                xseries.IsValueShownAsLabel = True
                xseries.IsVisibleInLegend = True
                xseries.IsXValueIndexed = True
    
                xseries.ChartType = Charting.SeriesChartType.Column
                xseries.Color = Color.Blue
    
                grpGrafico4.ChartAreas(0).AxisX.Minimum = 0
                grpGrafico4.ChartAreas(0).AxisX.Maximum = 10
                'grpGrafico4.ChartAreas(0).AxisX.Maximum = 11
                'grpGrafico4.ChartAreas(0).AxisX.Interval = 0.5
    
                grpGrafico4.ChartAreas(0).AxisX.MajorGrid.Enabled = True
                grpGrafico4.ChartAreas(0).AxisX.IsMarginVisible = True
    
                For i As Integer = 0 To cxFruits.Length - 1
    
                    xseries.Points.AddXY(s_cxFruits(i), s_cySale(i))
    
                Next
    
                Me.grpGrafico4.Series.Add(xseries)
    
            Catch ex As Exception
    
                Dim s_dsErro As String = String.Empty
                s_dsErro = ex.StackTrace
                MessageBox.Show(s_dsErro)
    
            End Try
    
        End Sub

    Monday, July 16, 2018 10:27 PM

Answers

  • Hi neibala,

    Thank you for posting here.

    For your question, there are too many labels and X axis starts skipping some of them. Solution is to set Axis.Interval property to 1.

    Please try the code below. I use Chart1 to replace grpGrafico4 in your code.

    Imports System.Windows.Forms.DataVisualization
    
    Public Class Chart
        Private cySale() As Double = {85241, 35210, 24560, 18425, 15000, 12500,
                                   8630, 7520, 4200, 3400}
    
        Private cxFruits() As String = {"Pear", "Apple", "Guava", "Peach", "Watermelon", "Banana", "Orange", "Khaki", "Melon", "Strawberry"}
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Try
                Dim s_cySale() As Double = {85241, 35210, 24560, 18425, 15000, 12500,
                                   8630, 7520, 4200, 3400}
    
                Dim s_cxFruits() As String = {"Pear", "Apple", "Guava", "Peach", "Watermelon ",
                               "Banana", "Orange", "Khaki", "Melon ", "Strawberry"}
    
                Chart1.Series.Clear()
                Chart1.Titles.Clear()
    
                Chart1.Titles.Add("Top Selling (Fruit) - 10 Most Sold Fruits 2018")
    
                Chart1.Titles(0).Font = New Font("Times New Roman", 18, FontStyle.Bold)
                Chart1.Titles(0).ForeColor = Color.Pink
    
                Chart1.AntiAliasing = Charting.AntiAliasingStyles.All
                Chart1.TextAntiAliasingQuality = Charting.TextAntiAliasingQuality.High
    
                Chart1.Palette = Charting.ChartColorPalette.Chocolate
    
                Dim xseries As Charting.Series = New Charting.Series With {
                    .IsValueShownAsLabel = True,
                    .IsVisibleInLegend = True,
                    .IsXValueIndexed = True,
                    .ChartType = Charting.SeriesChartType.Column,
                    .Color = Color.Blue
                }
    
                Chart1.ChartAreas(0).AxisX.Interval = 1
    
                'Chart1.ChartAreas(0).AxisX.Minimum = 0
                'Chart1
                'Chart1.ChartAreas(0).AxisX.Maximum = 10
                'Chart1.ChartAreas(0).AxisX.Interval = 0.5
    
                'Chart2
                'Chart1.ChartAreas(0).AxisX.Maximum = 11
                'Chart1.ChartAreas(0).AxisX.Interval = 0.5
    
                Chart1.ChartAreas(0).AxisX.MajorGrid.Enabled = True
                Chart1.ChartAreas(0).AxisX.IsMarginVisible = True
    
                For i As Integer = 0 To cxFruits.Length - 1
    
                    xseries.Points.AddXY(s_cxFruits(i), s_cySale(i))
    
                Next
    
                Chart1.Series.Add(xseries)
    
            Catch ex As Exception
    
                Dim s_dsErro As String = String.Empty
                s_dsErro = ex.StackTrace
                MessageBox.Show(s_dsErro)
    
            End Try
        End Sub
    
        Private Sub Chart_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    End Class

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by neibala Wednesday, July 18, 2018 4:04 PM
    Wednesday, July 18, 2018 2:03 AM
    Moderator

All replies

  • Hi neibala,

    Thank you for posting here.

    For your question, there are too many labels and X axis starts skipping some of them. Solution is to set Axis.Interval property to 1.

    Please try the code below. I use Chart1 to replace grpGrafico4 in your code.

    Imports System.Windows.Forms.DataVisualization
    
    Public Class Chart
        Private cySale() As Double = {85241, 35210, 24560, 18425, 15000, 12500,
                                   8630, 7520, 4200, 3400}
    
        Private cxFruits() As String = {"Pear", "Apple", "Guava", "Peach", "Watermelon", "Banana", "Orange", "Khaki", "Melon", "Strawberry"}
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Try
                Dim s_cySale() As Double = {85241, 35210, 24560, 18425, 15000, 12500,
                                   8630, 7520, 4200, 3400}
    
                Dim s_cxFruits() As String = {"Pear", "Apple", "Guava", "Peach", "Watermelon ",
                               "Banana", "Orange", "Khaki", "Melon ", "Strawberry"}
    
                Chart1.Series.Clear()
                Chart1.Titles.Clear()
    
                Chart1.Titles.Add("Top Selling (Fruit) - 10 Most Sold Fruits 2018")
    
                Chart1.Titles(0).Font = New Font("Times New Roman", 18, FontStyle.Bold)
                Chart1.Titles(0).ForeColor = Color.Pink
    
                Chart1.AntiAliasing = Charting.AntiAliasingStyles.All
                Chart1.TextAntiAliasingQuality = Charting.TextAntiAliasingQuality.High
    
                Chart1.Palette = Charting.ChartColorPalette.Chocolate
    
                Dim xseries As Charting.Series = New Charting.Series With {
                    .IsValueShownAsLabel = True,
                    .IsVisibleInLegend = True,
                    .IsXValueIndexed = True,
                    .ChartType = Charting.SeriesChartType.Column,
                    .Color = Color.Blue
                }
    
                Chart1.ChartAreas(0).AxisX.Interval = 1
    
                'Chart1.ChartAreas(0).AxisX.Minimum = 0
                'Chart1
                'Chart1.ChartAreas(0).AxisX.Maximum = 10
                'Chart1.ChartAreas(0).AxisX.Interval = 0.5
    
                'Chart2
                'Chart1.ChartAreas(0).AxisX.Maximum = 11
                'Chart1.ChartAreas(0).AxisX.Interval = 0.5
    
                Chart1.ChartAreas(0).AxisX.MajorGrid.Enabled = True
                Chart1.ChartAreas(0).AxisX.IsMarginVisible = True
    
                For i As Integer = 0 To cxFruits.Length - 1
    
                    xseries.Points.AddXY(s_cxFruits(i), s_cySale(i))
    
                Next
    
                Chart1.Series.Add(xseries)
    
            Catch ex As Exception
    
                Dim s_dsErro As String = String.Empty
                s_dsErro = ex.StackTrace
                MessageBox.Show(s_dsErro)
    
            End Try
        End Sub
    
        Private Sub Chart_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    End Class

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by neibala Wednesday, July 18, 2018 4:04 PM
    Wednesday, July 18, 2018 2:03 AM
    Moderator
  • Wendy Zang

        Thanks for the explanations which was very helpful and I realized where I was doing incorrectly.

    Wednesday, July 18, 2018 4:03 PM