I have the following code to make a pie chart:
public void MakeChart (List<Report> data)
{
var chart = new RadPieChart ();
var series = new PieSeries ();
series.SetBinding (PieSeries.ItemsSourceProperty, new Binding ("Data"));
series.ValueBinding = new PropertyNameDataPointBinding ("Value");
series.LabelBinding = new PropertyNameDataPointBinding ("Title");
series.ShowLabels = true;
series.AllowSelect = true;
chart.Series.Add (series);
var selection = new ChartSelectionBehavior ();
selection.SeriesSelectionMode = ChartSelectionMode.None;
selection.DataPointSelectionMode = ChartSelectionMode.Single;
selection.SelectionChanged += Selection_SelectionChanged;
chart.Behaviors.Add (selection);
chart.BindingContext = new ViewModel (data);
ChartLayout.Children.Add (chart);
}
void Selection_SelectionChanged (object sender, EventArgs e)
{
DisplayAlert ("Hello", "hi", "OK");
}
The pie chart it self is working fine. But when I add the event handler, then I get the "Object reference not set to an instance of an object" with the following StackTrace
System.NullReferenceException: Object reference not set to an instance of an object
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at Dashboard.iOS.Application.Main (System.String[] args) [0x00008] in /Users/muhammadali/Dropbox/_Techsource_Mobile/Dashboard/iOS/Main.cs:17
Please help.