StockChart generating exception on Load (sometimes!)

I'm having an inconsistent problem with StockChart, where it is generating an exception on load with some examples, and not others. Problem is I can't isolate when/why.

The exception being generated is:

crit:Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

Unhandled exception rendering component:Object reference notset to an instance of an object.
System.NullReferenceException:Object reference notset to an instance of an object.
at Syncfusion.Blazor.Charts.SfStockChart.CalculateSeriesXMinMax()
at Syncfusion.Blazor.Charts.SfStockChart.RenderStockChart(Boolean isRender)
at Syncfusion.Blazor.Charts.SfStockChart.OnAfterScriptRendered()
at Syncfusion.Blazor.SfBaseComponent.OnAfterRenderAsync(Boolean firstRender)
at Syncfusion.Blazor.SfDataBoundComponent.OnAfterRenderAsync(Boolean firstRender)
at Syncfusion.Blazor.Charts.SfStockChart.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle,ComponentState owningComponentState)

To help you help me, I have generated a simple example, that fails as described using the simplest example fromSyncfusion online documentation (https://blazor.syncfusion.com/documentation/stock-chart/working-with-data ). In the example, navigate to the OrgUnits page to observe the failure.

Curiously, I have some other more complicated examples, that do load without failure.

I have attached the project. Please advise!

Regards,

Phil


Attachment: DemoFail_StockChart_1_dbffda32.zip


4 Replies

DG Durga Gopalakrishnan Syncfusion Team July 29, 2022 12:50 PM UTC

Hi Phil,


Greetings from Syncfusion.


We have ensured your reported scenario with attached exception. We suggest you to declare the properties with get, set accessor to resolve the reported problem. We have attached the modified sample for your reference. Please check with below snippet.


@code {

    public class ChartData

        {

            public DateTime Date { get; set; }

            public Double Open { get; set; }

            public Double Low { get; set; }

            public Double Close { get; set; }

            public Double High { get; set; }

            public Double Volume { get; set; }

        }

}



Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/StockChart1841766387.zip


Kindly revert us if you have any concerns.


Regards,

Durga Gopalakrishnan.



PH Phil Holmes August 1, 2022 05:48 AM UTC

Ok Durga, so even though the code I provided was directly from your online documentation (reference provided, perhaps update), we've established that the issue relates to initialisation/instantiation.

There's still an issue there though if you are instantiating, and one needs to acquire data asynchronously.

Again, as I can't provide my working code, here is a failing example:

<SfStockChart Title="AAPL Stock Price" @ref="@sc">
    <StockChartSeriesCollection>
        <StockChartSeries DataSource="@StockDetails" Type="ChartSeriesType.Candle" XName="Date" High="High" Low="Low" Open="Open" Close="Close" Volume="Volume" Name="Google"></StockChartSeries>
    </StockChartSeriesCollection>
</SfStockChart>




@code {
    public DemoFail.Shared.OrgUnit ou;
    private List<ChartData> StockDetails { get; set; } = new List<ChartData>();
    private SfStockChart sc { get; set; }


    protected override async Task OnInitializedAsync() {
        await Task.Delay(5000);
        StockDetails = new List<ChartData> {
                 new ChartData { Date = new DateTime(2012, 04, 02), Open= 85.9757, High = 90.6657,Low = 85.7685, Close = 90.5257,Volume = 660187068},
                 new ChartData { Date = new DateTime(2012, 04, 09), Open= 89.4471, High = 92,Low = 86.2157, Close = 86.4614,Volume = 912634864},
                 new ChartData { Date = new DateTime(2012, 04, 16), Open= 87.1514, High = 88.6071,Low = 81.4885, Close = 81.8543,Volume = 1221746066},
                 new ChartData { Date = new DateTime(2012, 04, 23), Open= 81.5157, High = 88.2857,Low = 79.2857, Close = 86.1428,Volume = 965935749},
                 new ChartData { Date = new DateTime(2012, 04, 30), Open= 85.4, High = 85.4857,Low = 80.7385, Close = 80.75,Volume = 615249365},
                 new ChartData { Date = new DateTime(2012, 05, 07), Open= 80.2143, High = 82.2685,Low = 79.8185, Close = 80.9585,Volume = 541742692},
                 new ChartData { Date = new DateTime(2012, 05, 14), Open= 80.3671, High = 81.0728,Low = 74.5971, Close = 75.7685,Volume = 708126233},
                 new ChartData { Date = new DateTime(2012, 05, 21), Open= 76.3571, High = 82.3571,Low = 76.2928, Close = 80.3271,Volume = 682076215},
                 new ChartData { Date = new DateTime(2012, 05, 28), Open= 81.5571, High = 83.0714,Low = 80.0743, Close = 80.1414,Volume = 480059584}
        };
        sc.Refresh();
    }

This example, where the datasource is declared to be empty. then loaded async on initialisation fails similarly. To work around this failure, one must initialised the datasource to have some dummy data:

private List<ChartData> StockDetails = new List<ChartData>() { { new ChartData { Date = new DateTime(2012, 04, 02), Open = 85.9757, High = 90.6657, Low = 85.7685, Close = 90.5257, Volume = 660187068 } } };

I think its a bug that the chart can't handle being declared, then data populated async on init.

Please advise.

Regards,

Phil





DG Durga Gopalakrishnan Syncfusion Team August 1, 2022 02:23 PM UTC

Hi Phil,


We have considered your reported scenario as bug and logged a defect report for this issue. This fix will be available in our weekly patch release which is scheduled to be rolled out on 16th August 2022. We appreciate your patience until then. You can keep track of the bug from the below feedback link.


Feedback Link :  https://www.syncfusion.com/feedback/36738/console-error-when-stockchart-datasource-is-empty


If you have any more specification/precise replication procedure or a scenario to be tested, you can add it as a comment in the portal.


Regards,

Durga Gopalakrishnan.



DG Durga Gopalakrishnan Syncfusion Team August 23, 2022 04:26 PM UTC

Hi Phil,


We are glad to announce that our v20.2.0.45 patch release is rolled out; we have added the fix for reported issue. You can use the latest Syncfusion.Blazor.Charts NuGet package.


NuGet Package : https://www.nuget.org/packages/Syncfusion.Blazor.Charts/


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.


Regards,

Durga Gopalakrishnan.


Loader.
Up arrow icon