Basic Usage
To get a Line Chart use ChartType="ChartType.Line" to render the configured ChartSeries as line graphs.
Like in the other chart types, the Series in the chart are clickable. You can bind SelectedIndex to make your chart interactive.
Using the ChartOptions you can change the thickness of the lines by setting the parameter LineStrokeWidth.
Fossil
Renewable
Selected: None
<div> <MudChart ChartType="ChartType.Line" ChartSeries="" @bind-SelectedIndex="Index" XAxisLabels="" Width="100%" Height="350px" ChartOptions=""/> <MudGrid> <MudItem xs="6"> <MudText Typo="Typo.body1" Class="py-3">Selected: @(Index < 0 ? "None" : Series[Index].Name)</MudText> </MudItem> <MudItem xs="6"> <MudSlider @bind-Value="Options.LineStrokeWidth" Min="1" Max="10" Color="Color.Info">Line Width: @Options.LineStrokeWidth.ToString()</MudSlider> </MudItem> </MudGrid> </div>
@code { private int Index = -1; //default value cannot be 0 -> first selectedindex is 0. public ChartOptions Options = new ChartOptions(); public List<ChartSeries> Series = new List<ChartSeries>() { new ChartSeries() { Name = "Fossil", Data = new double[] { 90, 79, 72, 69, 62, 62, 55, 65, 70 } }, new ChartSeries() { Name = "Renewable", Data = new double[] { 10, 41, 35, 51, 49, 62, 69, 91, 148 } }, }; public string[] XAxisLabels = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep" }; }
Y-Axis Ticks
Using the ChartOptions you can also change tick interval of the Y-axis by setting parameter YAxisTicks.
Chernobyl-1
Chernobyl-2
Chernobyl-3
Chernobyl-4
<div> <MudChart ChartType="ChartType.Line" ChartSeries="@_series" XAxisLabels="@_xAxisLabels" ChartOptions="@_options" Width="100%" Height="350px"></MudChart> <MudSlider @bind-Value="_options.YAxisTicks" Min="10" Max="400" Step="10" Color="Color.Info">Y-Axis Ticks: @_options.YAxisTicks.ToString()</MudSlider> </div>
@code { private readonly List<ChartSeries> _series = new(); private readonly ChartOptions _options = new(); private readonly string[] _xAxisLabels = { "1986-04-20", "1986-04-21", "1986-04-22", "1986-04-23", "1986-04-24", "1986-04-25", "1986-04-26" }; protected override void OnInitialized() { double[] data1 = { 65, 68, 70, 74, 74, 72, 74 }; double[] data2 = { 88, 90, 91, 92, 91, 90, 90 }; double[] data3 = { 89, 91, 92, 92, 92, 92, 91 }; double[] data4 = { 85, 86, 90, 90, 92, 99, 0 }; _series.Add(new ChartSeries { Name = "Chernobyl-1", Data = data1 }); _series.Add(new ChartSeries { Name = "Chernobyl-2", Data = data2 }); _series.Add(new ChartSeries { Name = "Chernobyl-3", Data = data3 }); _series.Add(new ChartSeries { Name = "Chernobyl-4", Data = data4 }); _options.YAxisTicks = 50; StateHasChanged(); } }