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 annotation throws an exception

Hello 

I am using the SfChart component at my project and I have added a chart annotation on the chart.


So when I run my project there are a lot of times that I get this exception:

2023-03-03 15:57:31.146 +02:00 [WRN] Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Syncfusion.Blazor.Charts.Internal.ChartAnnotationRenderer.SetAnnotationPixelValue()
   at Syncfusion.Blazor.Charts.Internal.ChartAnnotationRenderer.CalculateRenderingOption()
   at Syncfusion.Blazor.Charts.ChartAnnotation.OnParametersSet()
   at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)


I am posting below the SfChart component that I am using at my project


      <SfChart    ID="Chart"
                         Height="50%"
                         Width="95%"
                         Title=My chart
                         Background="transparent"
                         Palettes="OeePalettes">
                            <ChartAnnotations>
                                <ChartAnnotation X="150" Y="70" CoordinateUnits="Units.Pixel">
                                    <ContentTemplate>
                                        <div style="color: #ffffff; font-size: medium; font-style: italic;margin:auto;">Need more data...</div>
                                    </ContentTemplate>
                                </ChartAnnotation>
                            </ChartAnnotations>
                            <ChartTitleStyle Size="18px" Color="#FFFFFF"></ChartTitleStyle>
                            <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime" Format="dd MMM HH:mm" LabelRotation="90" Interval="1">
                                <ChartAxisLabelStyle Color="#FFFFFF" />
                            </ChartPrimaryXAxis>
                            <ChartPrimaryYAxis>
                                <ChartAxisLabelStyle Color="#FFFFFF" />
                            </ChartPrimaryYAxis>
                            <ChartTooltipSettings Enable="true"></ChartTooltipSettings>
                            <ChartSeriesCollection>
                                <ChartSeries DataSource="@MyDatasource"
                                     XName="@XName"
                                     YName="@YName"
                                     Type="ChartSeriesType.Line"
                                     Width="0">
                                </ChartSeries>
                            </ChartSeriesCollection>
                        </SfChart>


Any ideas where this exception is coming from ?

Thanks in advance!

4 Replies

DG Durga Gopalakrishnan Syncfusion Team March 6, 2023 10:54 AM UTC

Hi Amanda,


Greetings from Syncfusion.


We have ensured your reported scenario with your attached code snippet. Chart annotation is rendered properly without any exception. We have attached the tested sample and screenshot for your reference. Please check with below snippet and sample.


<SfChart>

   <ChartAnnotations>

        <ChartAnnotation X="@x" Y="@y" CoordinateUnits="Units.Pixel">

            <ContentTemplate>

                <div style="font-size: medium; font-style: italic;margin:auto;">Need more data...</div>

            </ContentTemplate>

        </ChartAnnotation>

    </ChartAnnotations>

</SfChart>

@code {

    public string x ="150px";

    public string y = "70px";

}



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


UG : https://blazor.syncfusion.com/documentation/chart/chart-annotations


Since we are unable to replicate an issue from our end, we request you to share the following information which will be helpful for further analysis and provide you the solution sooner.

  • Try to reproduce the reported scenario in above sample.
  • Please share your sample (or) code snippet with full configurations.
  • Share the details if you have done any other customization in your sample.
  • Share your datasource file.
  • Share your NuGet package version.


Kindly revert us if you have any concerns.


Regards,

Durga Gopalakrishnan.



KJ Kevin J May 30, 2023 06:48 PM UTC

I'm also getting a very similar exception, any update on what is causing it? Using Syncfusion.Blazor 21.2.6

The exception only occurs upon reloading the graph. In our application we have the option to switch between table view and graph view. Graph view is the default view and loads fine the first time but when switching back to the graph view from table view it throws the following exception.

blazor.server.js:1 [2023-05-30T18:18:26.533Z] Error: System.NullReferenceException: Object reference not set to an instance of an object.

   at Syncfusion.Blazor.Charts.Internal.ChartAnnotationRenderer.SetAnnotationPixelValue()

   at Syncfusion.Blazor.Charts.Internal.ChartAnnotationRenderer.CalculateRenderingOption()

   at Syncfusion.Blazor.Charts.ChartAnnotation.OnParametersSet()

   at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()

   at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)

   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)



GV Gopalakrishnan Veeraraghavan Syncfusion Team May 31, 2023 01:42 PM UTC

Hi Kevin,


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


Feedback Link: Exception occurs when rendering the chart with annotations in the DashboardLayout component in Blazor | Feedback Portal (syncfusion.com)


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,

Gopalakrishnan Veeraraghavan



GV Gopalakrishnan Veeraraghavan Syncfusion Team June 6, 2023 01:18 PM UTC

Kevin,


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


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ChartAnnotation1468547880_(3)_(1)202654793.zip


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,

Gopalakrishnan Veeraraghavan


Loader.
Live Chat Icon For mobile
Up arrow icon