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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ChartAnnotations error

Thread ID:

Created:

Updated:

Platform:

Replies:

150138 Dec 22,2019 06:24 PM UTC Dec 24,2019 12:18 PM UTC Xamarin.Forms 2
loading
Tags: SfChart
Marco Salvatori
Asked On December 22, 2019 06:24 PM UTC

Hello,
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:
            try
            {
                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;
                        layout.Children.Add(image);
                        annotation.View = layout;
                        ChartTemp.ChartAnnotations.Add(annotation);
                    }
                    else
                    {
                    }
                    conta += 1;
                }
            }
            catch (Exception ex)
            {

                //throw;
            }

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 }

Thanks

Marco Salvatori
Replied On 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);
                     }

Hemalatha Marikumar [Syncfusion]
Replied On 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. 
  
Regards, 
Hemalatha M. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon