Skip to main content

Stacked bar chart

info

Charts are available with Avalonia Pro.

Stacked bar charts represent multiple series of data stacked on top of each other, allowing for comparison of both the total and the individual components.

Stacked bar chart with colored segments stacked in each bar showing regional sales contributions per quarter.

When to use

  • Part-to-Whole: Visualizing how many smaller parts make up a larger total category.
  • Categorical comparison: Comparing totals across different groups while seeing internal distribution.
  • Space optimization: Showing multiple data series without needing separate bars for each.

Code example

XAML

<charts:CartesianChart Name="StackedBarChart" Title="Stacked Bar Chart" Height="250" ShowLegend="True">
<charts:CartesianChart.HorizontalAxis>
<charts:CategoryAxis />
</charts:CartesianChart.HorizontalAxis>
<charts:CartesianChart.VerticalAxis>
<charts:NumericalAxis />
</charts:CartesianChart.VerticalAxis>
<charts:CartesianChart.Series>
<charts:StackedBarSeries Title="Product A" ItemsSource="{Binding StackedBarProductA}" Fill="DodgerBlue" />
<charts:StackedBarSeries Title="Product B" ItemsSource="{Binding StackedBarProductB}" Fill="Orange" />
<charts:StackedBarSeries Title="Product C" ItemsSource="{Binding StackedBarProductC}" Fill="Green" />
</charts:CartesianChart.Series>
</charts:CartesianChart>

Data model (C#)

public ObservableCollection<int> StackedBarProductA { get; } = new()
{
40, 55, 50, 60, 45, 70
};

public ObservableCollection<int> StackedBarProductB { get; } = new()
{
30, 35, 40, 45, 35, 50
};

public ObservableCollection<int> StackedBarProductC { get; } = new()
{
20, 25, 30, 25, 30, 35
};

Common properties (StackedBarSeries)

PropertyDescriptionDefault
TitleThe name shown in the legend.null
ItemsSourceThe collection of data for this specific part of the stack.null
CategoryPathPath to the shared category value for each bar.null
ValuePathPath to the numeric value for this series.null
FillBackground color for this series segment.Auto-generated
StackGroupIdentifier used to stack related series together."default"
BarWidthWidth of each bar as a fraction of the available slot.0.7
BarCornerRadiusRounding for the bar segments.0