Xceed Chart for WinForms v4.4 Documentation
Welcome to Xceed Chart for WinForms v4.4 / User Guide / Series / Bar Series / Stacked Bar

In This Topic
    Stacked Bar
    In This Topic

    Stacked bars are created by using several instances of the BarSeries class. The first bar series created must have its MultiBarMode property set to MultiBarMode.Series. The MultiBarMode property of the subsequent bar series must be set to MultiBarMode.Stacked. Stacked bar series are displayed on top of each other. The following figure shows a typical stack bar chart: 



    figure 1.

    Creating the Stacked Bar Series

    The following example demonstrates how to create a stack bar chart with two stacks:

    VB.NET  

    ' there is one chart created by default

    Dim chart As Chart = CType(chartControl1.Charts(0), Chart)

     

    Dim bar1 As BarSeries = CType(chart.Series.Add(SeriesType.Bar), BarSeries)

    Dim bar2 As BarSeries = CType(chart.Series.Add(SeriesType.Bar), BarSeries)

     

    bar1.MultiBarMode = MultiBarMode.Series

    bar2.MultiBarMode = MultiBarMode.Stacked

    C#  
    // there is one chart created by default
    Chart chart = (Chart)chartControl1.Charts[0];
    BarSeries bar1 = (BarSeries)chart.Series.Add(SeriesType.Bar);
    BarSeries bar2 = (BarSeries)chart.Series.Add(SeriesType.Bar);
    bar1.MultiBarMode = MultiBarMode.Series;
    bar2.MultiBarMode = MultiBarMode.Stacked;

    If you want to create a second stack bar with two stacks behind the stack bar created in the previous sample, you must add the following code:

    VB.NET  

    Dim bar4 As BarSeries = CType(Chart.Series.Add(SeriesType.Bar), BarSeries)

    Dim bar5 As BarSeries = CType(Chart.Series.Add(SeriesType.Bar), BarSeries)

     

    bar4.MultiBarMode = MultiBarMode.Series

    bar5.MultiBarMode = MultiBarMode.Stacked

    C#  
    BarSeries bar4 = (BarSeries)Chart.Series.Add(SeriesType.Bar);
    BarSeries bar5 = (BarSeries)Chart.Series.Add(SeriesType.Bar);
    bar4.MultiBarMode = MultiBarMode.Series;
    bar5.MultiBarMode = MultiBarMode.Stacked;

    Stack Origin

    When a bar series is stacked it is always displayed with origin 0, regardless of the values of the UseOrigin and Origin properties.

    Stacks with Negative Values

    Stacked bar charts support negative values, which means that if you insert negative values in the Values data series, the respective stacks will be piled below the zero. In this case since the values for a concrete category can be both positive and negative the chart will display two piles for each category: one for the positive values, which grows above the zero, and another one for the negative values, which grows below the zero. 

    The following figure demonstrates a typical stack bar chart with negative and positive values: 



    figure 2.

    Stacked Bar Formatting Commands

    The following formatting commands inherited from the Series class have different meanings when a bar series is stacked: 

    <total> - Displays the positive or negative value sum of the values in the current stack. If the current value is negative, the negative sum is displayed. Otherwise, the positive sum is displayed.

    <cumulative> - Displays the sum of the values up to the current stack value.
    <percent> - Displays the percent contribution of the value to the total pile sum. 

    Related Examples

    Windows Forms: Series\Bar\Stacked Bar

    See Also

    BarSeries