Hey I have a Radzen line chart, where the data source is a List<>. Every second, I add data to the list and call an reload for the chart. My problem is that the Chart wont update, no mater what i do.
You need to either call the Reload method of the chart or update the list variable e.g. list = liist.ToList()
.
Its allready a List and the Reaload function has no effect.
I tried the following and it seems to work as expected:
<RadzenChart @ref=@chart SeriesClick=@OnSeriesClick>
<RadzenPieSeries Data="@revenue" Title="Revenue" CategoryProperty="Quarter"
ValueProperty="Revenue" />
</RadzenChart>
<RadzenButton Text="Add" Click=@OnClick />
@code {
RadzenChart chart;
void OnClick()
{
revenue.Add(new DataItem
{
Quarter = $"Q{revenue.Count}",
Revenue = revenue.Count * 10000
});
chart.Reload();
}
class DataItem
{
public string Quarter { get; set; }
public double Revenue { get; set; }
}
List<DataItem> revenue = new List<DataItem> {
new DataItem
{
Quarter = "Q1",
Revenue = 30000
},
new DataItem
{
Quarter = "Q2",
Revenue = 40000
},
new DataItem
{
Quarter = "Q3",
Revenue = 50000
},
new DataItem
{
Quarter = "Q4",
Revenue = 80000
},
};
}
I have it like this and it dont work
<RadzenChart @ref="myChart">
<RadzenLineSeries Data="viewmodell.MeasureItems" CategoryProperty="Time" Title="2019" LineType="LineType.Dashed" ValueProperty="Percentage">
<RadzenMarkers MarkerType="MarkerType.Square" />
</RadzenLineSeries>
</RadzenChart>
@code {
RadzenChart myChart;
..
..
..
private async void ViemodelPropertyChanged(object sender, PropertyChangedEventArgs e)
{
await InvokeAsync(() =>
{
try
{
myChart.Reload();
StateHasChanged();
}
catch (ObjectDisposedException disposed)
{
//Todoo:
}
});
}
And the ViewModdel Class with the List
....
public List<MeasureItem> MeasureItems
{ get
{
return measureItems;
}
set
{
measureItems = value;
}
}
....
This is an anti pattern and should not be used. Try making it async Task
. Also if there is an ObjectDisposedException things won't work for sure.
I have attached a working demo - you can start from it.
I have to use async void because i subscribe the methode to an event.
The Reload() is called right, so the ObjectDisposedException is not the problem