We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Chart does not load data on first load and logs error when refreshed

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



4 Replies 1 reply marked as answer

DG Durga Gopalakrishnan Syncfusion Team December 29, 2022 03:18 PM UTC

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.



DG Durga Gopalakrishnan Syncfusion Team January 3, 2023 03:10 PM UTC

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.



IM Isaac Mane January 4, 2023 11:06 AM UTC

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