Open ADringer opened 3 years ago
@ADringer I'm running into the same exception with a different library, anyway the scenario is the same: getting data from an external source through an HTTP request. Were you able to fix it somehow? It seems more something related to the framework rather than something specific to the libraries
@fleed yes, was able to get round this by moving my code round a little.
The issue I think is mainly with the OnInitializedAsync()
override. So what I've done is moved my chart initialization into the OnInitialized()
override instead e.g:
protected override void OnInitialized()
{
_chart = new BarConfig
{ ... }
}
And then do the async HTTP call in the OnAfterRenderAsync
override instead:
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// HTTP call
}
}
Hope that helps!
This looks like a timing issue. The OnInitializedAsync call may not have been completed before Blazor makes its first render, so _chart would have been null. There are three ways you can work around this:
BarConfig _chart = new BarConfig()
. Replace the _chart variable when you get the data and call StateHasChanged()
InvokeAsync(StateHasChanged)
.@if
statement:
@if(_chart != null){ <Chart Config="_chart" @ref="chartjs"></Chart> }
I'll go ahead and close this issue.
Describe the bug
I have a strong feeling it's a user issue, but I'm getting the following error when trying to view a chart in my wasm project:
Which Blazor project type is your bug related to?
Which charts does this bug apply to?
Bar chart
To Reproduce
Steps to reproduce the behavior: Create a Blazor WASM project.
Added the following to index.html in the client app:
The following in
_imports.razor
:And the razor component:
Expected behavior
Error logged in the console.
I imagine I've done something obviously wrong, so apologies for using your time!