Stacked Bar chart don't add correctly

23 Views Asked by At

I am using System.Web.UI.DataVisualization.Charting and vb.net to create a chart with stacked bars. This works fine, except one thing.

I first have a For Each loop that creates a set of series. These adds up nicely as stacked bars. The series are created within the loop.

Then I add another series outside the loop. This series do not add up to the series created inside the loop, but starts a new bar overwriting the bars created within the loop. So it is clearly not associated with the other series.

Why is this, and how to avoid it? I guess this is because the series StackValues is hidden inside the loop, but still same chart?

Pseudocode:

           For Each LoggingDevice In DeviceLogging.LoggingDevices
                Dim StackValues As Series = Pwrchart.Series.Add(LoggingDevice.DeviceID)
                StackValues.ChartType = SeriesChartType.StackedColumn
                
        (add some points)

                Pwrchart.Series.Add(StackValues)
            Next

            Dim DiffValues As Series = Pwrchart.Series.Add("Unknown")
            DiffValues.ChartType = SeriesChartType.StackedColumn
            (add some points)

        Pwrchart.Series.Add(DiffValues)
0

There are 0 best solutions below