Bar Chart

Represents a chart which displays series values as rectangular bars.

Rendered in 0 ms

Months 020406080SalesJanFebMarAprMayJunJulAugSep
United States
Germany
Sweden

Selected: None

Chart Height: 350px

XAxis Label Rotation

<MudPaper Class="doc-section-component-container">
    <MudChart ChartType="ChartType.Bar" ChartSeries="@_series" @bind-SelectedIndex="_index" ChartLabels="@_xAxisLabels" ChartOptions="_axisChartOptions"
              Width="100%" Height="@($"{_height}px")" MatchBoundsToSize="@_matchBoundsToSize"></MudChart>
</MudPaper>

<MudGrid>
    <MudItem xs="6">
        <MudText Typo="Typo.body1" Class="py-3">Selected: @(_index < 0 ? "None" : _series[_index].Name)</MudText>
    </MudItem>
    <MudItem md="6" xs="12">
        <MudCheckBox @bind-Value="_matchBoundsToSize" Color="Color.Primary" Label="MatchBoundsToSize"></MudCheckBox>
    </MudItem>
    <MudItem md="6" xs="12">
        <MudSlider @bind-Value="_height" Min="150" Max="500" Step="50">@($"Chart Height: {_height}px")</MudSlider>
    </MudItem>
    <MudItem md="6" xs="12">
        <MudSlider @bind-Value="_axisChartOptions.XAxisLabelRotation" Min="0" Max="90" Step="15">XAxis Label Rotation</MudSlider>
    </MudItem>
</MudGrid>
@code {

    private int _index = -1; //default value cannot be 0 -> first selectedindex is 0.
    private int _height = 350;
    private bool _matchBoundsToSize = false;
    private BarChartOptions _axisChartOptions = new BarChartOptions() 
    {
        XAxisTitle = "Months",
        YAxisTitle = "Sales",
        FixedBarWidth = 8,
    };
    private List<ChartSeries<double>> _series = new()
    {
        new() { Name = "United States", Data = new double[] { 40, 20, 25, 27, 46, 60, 48, 80, 15 } },
        new() { Name = "Germany", Data = new double[] { 19, 24, 35, 13, 28, 15, 13, 16, 31 } },
        new() { 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
020406080JanFebMarAprMayJunJulAugSep I Love MudBlazor!
United States
Germany
Sweden
<MudChart ChartType="ChartType.Bar" ChartSeries="@Series" ChartLabels="@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<double>> Series = new()
    {
        new() { Name = "United States", Data = new double[] { 40, 20, 25, 27, 46, 60, 48, 80, 15 } },
        new() { Name = "Germany", Data = new double[] { 19, 24, 35, 13, 28, 15, 13, 16, 31 } },
        new() { Name = "Sweden", Data = new double[] { 8, 6, 11, 13, 4, 16, 10, 16, 18 } },
    };
    public string[] XAxisLabels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep" };
}
An unhandled error has occurred. Reload 🗙