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:RadCartesianChart.Behaviors>
<telerikChart:ChartSelectionBehavior DataPointSelectionMode="Single" SeriesSelectionMode="None" SelectionChanged="SelectionChangedHandler" />
</telerikChart:RadCartesianChart.Behaviors>
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.
Regards,
Pavel R. Pavlov
Telerik
Hi all!
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:
<
telerikChart:RadCartesianChart.Behaviors
>
<
telerikChart:ChartSelectionBehavior
SeriesSelectionMode
=
"Single"
DataPointSelectionMode
=
"None"
SelectionChanged
=
"ChartSelectionBehavior_OnSelectionChanged"
/>
</
telerikChart:RadCartesianChart.Behaviors
>
Series creation code:
01.
new
LineSeries
02.
{
03.
StrokeThickness = 3,
04.
DisplayName = aName,
05.
AllowSelect =
true
,
06.
ItemsSource = ...,
07.
ValueBinding =
new
PropertyNameDataPointBinding(
"ValueProperty"
),
08.
CategoryBinding =
new
PropertyNameDataPointBinding(
"DateProperty"
)
09.
};
Selection Changed handling:
1.
private
void
ChartSelectionBehavior_OnSelectionChanged(
object
sender, EventArgs e)
2.
{
3.
// Have data point annotations appear only for selected series
4.
TheChart.Series?.ForEach(ser => ser.ShowLabels =
false
);
5.
var selectionBehavior = (ChartSelectionBehavior) sender;
6.
selectionBehavior.SelectedSeries?.ForEach(ser=>ser.ShowLabels =
true
);
7.
}
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.
Regards,
Pavel R. Pavlov
Telerik
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.
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.
Regards,
Pavel R. Pavlov
Telerik by Progress
Hi,
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
Anish
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.
Regards,
Didi
Progress Telerik
Hi Lakshmi
I think You need to use <telerikChart:RadCartesianChart.ChartBehaviors> instead of <telerikChart:RadCartesianChart.Behaviors>