Stacked percent 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.StackedPercent. Stacked percent bar series are displayed on top of each other, and all stacks begin at 0 and end at 1. The following figure shows a typical stack percent bar chart:
figure 1.
Creating the Stacked Percent Bar Series
The following example demonstrates how to create a stacked percent bar chart with three stacks:
VB.NET | |
---|---|
|
C# | |
---|---|
// there is one chart created by default BarSeries bar1 = (BarSeries)chart.Series.Add(SeriesType.Bar); bar1.MultiBarMode = MultiBarMode.Series; |
Stacked Percent Scaling
When a bar series is displayed in stacked percent mode, the min value of the series is always 0 and max value of the series is always 1. In order to display the texts on the PrimaryY axis as a percentage, you must use the following code:
VB.NET | |
---|---|
chart.Axis(StandardAxis.PrimaryY).ValueFormat.Format = ValueFormat.Percentage |
C# | |
---|---|
chart.Axis(StandardAxis.PrimaryY).ValueFormat.Format = ValueFormat.Percentage; |
Stacks with Negative Values
Stacked percent bar charts do not support negative values, meaning that all values are internally converted to their absolute value.
Stacked Percent Bar Formatting Commands
The following formatting commands inherited from the Series class have different meanings when a bar series is stacked:
<total> - Displays the absolute sum of the values in the current stack.
<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