apexcharts / Blazor-ApexCharts

A blazor wrapper for ApexCharts.js
https://apexcharts.github.io/Blazor-ApexCharts
MIT License
788 stars 91 forks source link

UpdateSeriesAsync Doesn't Update in Blazor-ApexCharts #373

Closed sezercanaktemur91 closed 8 months ago

sezercanaktemur91 commented 8 months ago

I have list named 'listTAPivotAll'. I want to update chart depending on user decision. Its dynamic. If user wants to display realtime or historical values, I'm assign relative list to that list.

I'm using UpdateSeriesAsync to update the chart however it doesn't updated, old values remains.

However if i re-call that function twice, it updates and x-axis labes are disappearing.

What could be the reason?

<ApexChart @ref="chart" TItem="Lists.list_TAPivot" Title="Top Activity" Options="options" Height="@("100%")">
       <ApexPointSeries TItem="Lists.list_TAPivot"
                 Items="listTAPivotAll"
                 Name="CPU"
                 SeriesType="SeriesType.Area"
                 XValue="e => e.SAMPLE_TIME"
                 YValue="e=> e.CPU"
                 OrderBy="e=>e.X" Color="#60C73C" />
</ApexChart>

private async Task getRealtime(){
    ... load listTAPivotHistoric
    listTAPivotAll = listTAPivotRealtime;
    await chart.UpdateSeriesAsync();
    //await chart.UpdateOptionsAsync(true,true,true);   --> I tried this one also, didn't work
    await InvokeAsync(StateHasChanged);

}

private async Task getHistoric(){
    ... load listTAPivotHistoric
    listTAPivotAll = listTAPivotHistoric;
    await chart.UpdateSeriesAsync();
    //await chart.UpdateOptionsAsync(true,true,true);  --> I tried this one also, didn't work
    await InvokeAsync(StateHasChanged);
}

Recording 2023-12-28 at 06 55 21

joadan commented 8 months ago

Hi,

Is it possible for you to provide a minimal repo to reproduce the issue?

sezercanaktemur91 commented 8 months ago

Hello,

the code have a lot of dependency, its too hard to make it.

However i was able do it like below. Almost tried every combination between UpdateSeries,UpdateOptions,RenderCharts etc.

This one worked.

listTAPivotAll.Clear();
await chart.RenderAsync();
listTAPivotAll = listTAPivotHistoric;
await chart.AppendDataAsync(listTAPivotAll);

However still X-Axis labels are not showing up after run above code like you can see previous gif that i attached.

joadan commented 8 months ago

I suspect your problem is how you bind data to the chart. Try to start as simple as possible using the samples as a starting point. I would recommend using the method UpdateOptionsAsync, this will update both the data and all options.

Also make sure you are on the latest version.

sezercanaktemur91 commented 8 months ago

For some reason, I need to load data after 'OnAfterRenderAsync'.

I think that is why I need to use always AppendData even for initial load.