How to create stacked bar with multiple series in Blazor Chart?
This article explains how to create stacking bar with multiple series in Blazor Chart.
Creating multiple stacking bar in Blazor Chart component
Blazor Charts provides a support to create stacked bar with multiple series. This can be achieved by using StackingGroup property.
For example, consider four stacking bar series grouped into two; Group1 and Group2 by using the StackingGroup property. Then, chart is rendered with two stacked bars at a point: one for Group1 and the other for Group2.
The following code example demonstrates how to render a stacked bar with multiple series in Blazor Chart.
Index.razor
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@DataSource" StackingGroup="Group1" XName="X" YName="YValue" Type="ChartSeriesType.StackingBar">
</ChartSeries>
<ChartSeries DataSource="@DataSource" StackingGroup="Group1" XName="X" YName="YValue1" Type="ChartSeriesType.StackingBar">
</ChartSeries>
<ChartSeries DataSource="@DataSource" StackingGroup="Group2" XName="X" YName="YValue2" Type="ChartSeriesType.StackingBar">
</ChartSeries>
<ChartSeries DataSource="@DataSource" StackingGroup="Group2" XName="X" YName="YValue3" Type="ChartSeriesType.StackingBar">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
public double YValue2 { get; set; }
public double YValue3 { get; set; }
}
public List<ChartData> DataSource = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56, YValue2=26,YValue3=50},
new ChartData { X= "GBR", YValue= 27, YValue1=17, YValue2=37,YValue3=20},
new ChartData { X= "CHN", YValue= 26, YValue1=36, YValue2=56,YValue3=26},
new ChartData { X= "UK", YValue= 56, YValue1=16, YValue2=36,YValue3=16},
new ChartData { X= "AUS", YValue= 12, YValue1=46, YValue2=26,YValue3=20},
new ChartData { X= "IND", YValue= 26, YValue1=16, YValue2=76,YValue3=25},
new ChartData { X= "DEN", YValue= 26, YValue1=12, YValue2=42,YValue3=20},
new ChartData { X= "MEX", YValue= 34, YValue1=32, YValue2=82,YValue3=35},
};
}
The following screenshot illustrate the output of the above code.
Output:
Conclusion
I hope you enjoyed learning how to create stacked bar with multiple series in Blazor Chart Component.
You can refer to our Blazor Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!