How to add dynamically in chart series into the Blazor Chart?

Answer:

We can add chart series dynamically by using addseries method in the button click. Here is the code snippet for your reference.

// add additional code here

<br />

<br />

<SfChart @ref="Chartobj">

<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Double">

<ChartSeriesCollection>

<ChartSeriesAnimation Enable="false"> ChartSeriesAnimation>

ChartSeries>

ChartSeriesCollection>

ChartPrimaryXAxis>

SfChart>

@code {

public void AddChartSeries()

{

List<ChartSeries> seriesCollection = new List<ChartSeries>();

seriesCollection.Add(new ChartSeries { Name = nameof(MyDataModel.XValue), XName = nameof(MyDataModel.XValue), YName = nameof(MyDataModel.YValue), DataSource = this.GetData(), Fill = colors[rnd.Next(colors.Length - 1)], Animation = new ChartSeriesAnimation { Enable = false } });

Chartobj.AddSeries(seriesCollection);

}

// add additional code here

}


Find the sample for to add dynamic chart series in Chart from here.


Loader.
Up arrow icon