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

ChartAnnotations error

I want to add a series of annotations to the graph (40 in all).
In the FOR loop it goes into error after the insertion of the first annotation and in the graph nothing is seen.
The code is this:
                ChartTemp.ChartAnnotations = new ChartAnnotationCollection();
                int conta = 0;
                foreach (var item in a.Forecast.Items)
                    if (item.DisplayHour / 6 == Convert.ToInt32(item.DisplayHour / 6))

                        ViewAnnotation annotation = new ViewAnnotation()
                            X1 = conta,
                            Y1 = 1,
                            VerticalAlignment = ChartAnnotationAlignment.Start
                        StackLayout layout = new StackLayout();
                        Image image = new Image();
                        image.Source = item.DisplayIcon;
                        image.HeightRequest = 15;
                        image.WidthRequest = 15;
                        annotation.View = layout;
                    conta += 1;
            catch (Exception ex)


the error is this:

"Object reference not set to an instance of an object."

{System.NullReferenceException: Object reference not set to an instance of an object.
  at Syncfusion.SfChart.XForms.Droid.SfChartRenderer.GetAnnotationCustomView (Syncfusion.SfChart.XForms.SfChart formChart, Xamarin.Forms.View template, Android.Views.ViewGroup+LayoutParams layoutParams) [0x0001d] in <a81794158d4f45a6a4d3f0bc69c29ef3>:0 
  at Com.Syncfusion.Charts.ViewAnnotation.OnPropertyChanged (System.String propertyName) [0x0002d] in <a81794158d4f45a6a4d3f0bc69c29ef3>:0 
  at Syncfusion.SfChart.XForms.Droid.ChartAnnotationMapping.GetNativeAnnotation (Syncfusion.SfChart.XForms.ChartAnnotation formsAnnotation, Syncfusion.SfChart.XForms.SfChart formChart) [0x0024c] in <a81794158d4f45a6a4d3f0bc69c29ef3>:0 
  at Syncfusion.SfChart.XForms.Droid.SfChartMapping.OnChartAnnotationCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00087] in <a81794158d4f45a6a4d3f0bc69c29ef3>:0 
  at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs(object,System.Collections.Specialized.NotifyCollectionChangedEventArgs)
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in <fb6d78e506844b3b96d5b35aa047fbbd>:0 
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00009] in <fb6d78e506844b3b96d5b35aa047fbbd>:0 
  at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (System.Int32 index, T item) [0x0001a] in <fb6d78e506844b3b96d5b35aa047fbbd>:0 
  at System.Collections.ObjectModel.Collection`1[T].Add (T item) [0x00020] in <d4a23bbd2f544c30a48c44dd622ce09f>:0 
  at STP.HomePage+<Start_Click>d__4.MoveNext () [0x00152] in D:\Professionale\STP\STP\STP\HomePage.xaml.cs:84 }


2 Replies

MS Marco Salvatori December 23, 2019 09:57 AM UTC

small upgrade
if I use this instruction:
ChartTemp.ChartAnnotations = a.ChartAnnotation;
gives me this error:
System.NullReferenceException: Object reference not set to an instance of an object.

if I use these instructions I have no errors:
                     foreach (var item in a.ChartAnnotation)
                         ChartTemp.ChartAnnotations.Add (item);

HM Hemalatha Marikumar Syncfusion Team December 24, 2019 12:18 PM UTC

Hi Marco, 
Greetings from Syncfusion. 
We have confirmed “NullException is thrown when we change the ChartAnnotations collection dynamically” as a bug and logged a defect report. The fix for this issue will be included in our upcoming weekly nuget release which is expected to rolled out by first week of January 2020. 
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 link above. 
We appreciate your patience until then. 
Hemalatha M. 

Live Chat Icon For mobile
Up arrow icon