United States
Germany
Sweden
Selected: None
Label Extra Height
Label Rotation
Bar Width Ratio
Legend Position
<MudPaper Class="doc-section-component-container"> <MudChart ChartType="ChartType.StackedBar" ChartSeries="@_series" @bind-SelectedIndex="_index" LegendPosition="@_legendPosition" XAxisLabels="@_xAxisLabels" Width="@_width" Height="@_height" AxisChartOptions="_axisChartOptions"></MudChart> </MudPaper> <MudGrid> <MudItem md="6" xs="12"> <MudText Typo="Typo.body1" Class="py-3">Selected: @(_index < 0 ? "None" : _series[_index].Name)</MudText> </MudItem> <MudItem md="6" xs="12"> <MudCheckBox @bind-Value="_axisChartOptions.MatchBoundsToSize" Color="Color.Info" Label="MatchBoundsToSize"></MudCheckBox> </MudItem> <MudItem md="6" xs="12"> <MudTextField @bind-Value="_width" Label="Chart Width"></MudTextField> </MudItem> <MudItem md="6" xs="12"> <MudTextField @bind-Value="_height" Label="Chart Height"></MudTextField> </MudItem> <MudItem md="6" xs="12"> <MudStack> <MudText Typo="Typo.body1">Label Extra Height</MudText> <MudSlider @bind-Value="_axisChartOptions.LabelExtraHeight" Min="0" Max="40" Step="5"></MudSlider> </MudStack> </MudItem> <MudItem md="6" xs="12"> <MudStack> <MudText Typo="Typo.body1">Label Rotation</MudText> <MudSlider @bind-Value="_axisChartOptions.LabelRotation" Min="0" Max="90" Step="15"></MudSlider> </MudStack> </MudItem> <MudItem md="6" xs="12"> <MudStack> <MudText Typo="Typo.body1">Bar Width Ratio</MudText> <MudSlider @bind-Value="_axisChartOptions.StackedBarWidthRatio" Min="0.1" Max="1" Step="0.1"></MudSlider> </MudStack> </MudItem> <MudItem md="6" xs="12"> <MudStack> <MudText Typo="Typo.body1">Legend Position</MudText> <MudRadioGroup T="Position" @bind-Value="_legendPosition"> <MudRadio Value="@(Position.Bottom)" Color="Color.Primary">Bottom</MudRadio> <MudRadio Value="@(Position.Top)" Color="Color.Primary">Top</MudRadio> <MudRadio Value="@(Position.Left)" Color="Color.Primary">Left</MudRadio> <MudRadio Value="@(Position.Right)" Color="Color.Primary">Right</MudRadio> <MudRadio Value="@(Position.Start)" Color="Color.Primary">Start</MudRadio> <MudRadio Value="@(Position.End)" Color="Color.Primary">End</MudRadio> </MudRadioGroup> </MudStack> </MudItem> </MudGrid>
@code { private int _index = -1; //default value cannot be 0 -> first selectedindex is 0. private string _width = "650px"; private string _height = "350px"; private AxisChartOptions _axisChartOptions = new() { StackedBarWidthRatio = 0.5 }; private Position _legendPosition = Position.Bottom; private List<ChartSeries> _series = new List<ChartSeries>() { new ChartSeries() { Name = "United States", Data = new double[] { 40, 20, 25, 27, 46, 60, 48, 80, 15 } }, new ChartSeries() { Name = "Germany", Data = new double[] { 19, 24, 35, 13, 28, 15, 13, 16, 31 } }, new ChartSeries() { Name = "Sweden", Data = new double[] { 8, 6, 11, 13, 4, 16, 10, 16, 18 } }, }; private string[] _xAxisLabels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep" }; }
Custom SVG Content
United States
Germany
Sweden
<MudChart ChartType="ChartType.StackedBar" ChartSeries="" XAxisLabels="" Width="100%" Height="350px"> <CustomGraphics> <style> .heavy { font: bold 30px Helvetica; } .Rrrrr { font: italic 40px Helvetica; fill: rgb(62,44,221); } </style> <text x="80" y="35" class="heavy">I Love</text> <text x="105" y="70" class="Rrrrr">MudBlazor!</text> </CustomGraphics> </MudChart>
@code { public List<ChartSeries> Series = new List<ChartSeries>() { new ChartSeries() { Name = "United States", Data = new double[] { 40, 20, 25, 27, 46, 46, 48, 44, 15 } }, new ChartSeries() { Name = "Germany", Data = new double[] { 19, 24, 35, 13, 28, 15, 13, 16, 40 } }, new ChartSeries() { Name = "Sweden", Data = new double[] { 8, 6, 11, 13, 4, 16, 10, 16, 20 } }, }; public string[] XAxisLabels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep" }; }