I am trying to highlight a selected bar in telerik bar chart control.
I tried the following code but I am not able to..
<telerikChart:ChartSelectionBehavior DataPointSelectionMode="Single" SeriesSelectionMode="None" SelectionChanged="SelectionChangedHandler" />
private void SelectionChangedHandler(object sender, EventArgs e)
var selectedPoint = (sender as ChartSelectionBehavior).SelectedPoints.FirstOrDefault();
please help regarding this.
8 Answers, 1 is accepted
I tried to reproduce the reported behavior on our side but it seems that the code works as expected. Could you please be more specific about the error you encounter? What is causing you to think you cannot select a data point?
Please refer to our online documentation and try to follow along the same and let us know if you can select any data point.
Pavel R. Pavlov
I appear to behaving a very similar problem to @Lakshmi. I am using a RadCartesianChart featuring a collection of LineSeries. Having followed the instructions at http://docs.telerik.com/devtools/xamarin/controls/chart/behaviors/chart-behaviors-selection-behavior I find that even though the selection changed event is fired, the SelectedSeries IEnumerable is always empty.
Relevant chart code:
Series creation code:
Selection Changed handling:
We can confirm there is an issue with the SelectionBehavior.SelectedSeries property. We logged it in our backlog system for fixing. Unfortunately, there is no workaround for the moment.
On the other hand, please note that the initial issue was reported for the SelectedPoints property and it is working as expected.
Pavel R. Pavlov
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;
var selection = new ChartSelectionBehavior ();
selection.SeriesSelectionMode = ChartSelectionMode.None;
selection.DataPointSelectionMode = ChartSelectionMode.Single;
selection.SelectionChanged += Selection_SelectionChanged;
chart.BindingContext = new ViewModel (data);
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
We already answered this question in your other thread. Since it is private I will copy and paste the same answer here so that others from the community can benefit.
We managed to reproduce the described problem and found a workaround for it. You just need to attach to the SelectionChanged event of the RadPieChart "later" (in the "OnAppearing" method) because in original code it is added "too early". Please find attached modifications that I made in order to overcome it.
Pavel R. Pavlov
Telerik by Progress
We using Barchart (RadCartesianChart) and the 'ChartSelectionBehavior ' is working IOS but its not working Android. In Android on selection the event is now firing but bar highlighting. Please share a solution
I have tried to reproduce the reported behavior but on our side it works fine. Could you provide some snippet, so I could research it further?
You can also find an example with selection behavior for RadChart control in our SDK Browser Application. Please take a look at it and let me know if you have any other questions on this.
I think You need to use <telerikChart:RadCartesianChart.ChartBehaviors> instead of <telerikChart:RadCartesianChart.Behaviors>