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