BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
I have a `sfChart` with two series and one axis. It is a line chart that shows trends over a period of time.
The problem with this chart is that it does not load data on initial load.
The chart shows this on first load
but when filtered by the dates, it loads correct data
Because the chart is refreshed when filters are applied, I decided to refresh the chart on load.
This makes the chart load data on init, but I get an error in the console.
here is what I'm working with
Hi Isaac,
Greetings from Syncfusion.
We have prepared sample with attached code snippet. Line charts are rendered properly with secondary axis and with assigned datasource at initial rendering itself. Please check with the below screenshot and sample.
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/ChartInitialLoad868675286.zip
Note : You can refresh the chart only when it is loaded. While trying to redraw the chart before it is loaded, then exception will be thrown.
Since we are unaware of exact scenario which replicates an issue, we request you to share the issue reproduced sample or try to replicate an issue in above sample and video reference so that it will be helpful to validate this case further from our end.
Please let us know if you have any other concerns.
Regards,
Durga Gopalakrishnan.
Issac,
When all chart elements are appended into DOM, then chart is in loaded stage. Using Loaded event, you can know chart is loaded. This event will be trigged after chart load. We have attached the sample for your reference.
<SfChart> <ChartEvents Loaded="LoadedEvent"></ChartEvents> </SfChart> @code { public void LoadedEvent(LoadedEventArgs args) { Console.WriteLine("Loaded event triggered"); } } |
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/LoadedEvt-1692107674.zip
API Reference : https://blazor.syncfusion.com/documentation/chart/events#loaded
Please let us know if you have any concerns.
Thank you for your reply.
How many times does the `LoadedEvent` method run? I was thinking of refreshing the chart in the method, but I'm sure this would crash the page because it will not stop running.
I'm not sure why this particular chart is not working as expected, though. All other charts are working perfectly except this one.
From the image i shared, if the OnInitializedAsync is changed to this:
I will get this error in the console
and I'm not sure exactly what is null.
This is what I have in the LoadChart method. I logged the data to the console to be sure it has data and it does. What exactly is wrong
Isaac,
We suggest you to call the chart RefreshAsync method only once to refresh the chart at initial rendering. We have attached modified sample for your reference. Please check with the below snippet and sample.
<SfChart @ref="chartObj"> <ChartEvents Loaded="OnChartLoaded"></ChartEvents> </SfChart> @code { public SfChart? chartObj; public bool initial = false; public void OnChartLoaded(LoadedEventArgs args) { if (!initial){ chartObj?.RefreshAsync(); initial = true; } } } |
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/ChartLoaded-1771031540.zip
If you are still facing problem, please try share a simple standalone sample which replicates the reported issue, so that it will be helpful to validate the reported scenario further from our end. Please let us know if you have any other concerns.