This is a migrated thread and some comments may be shown as answers.

chart selection behaviour is not working

8 Answers 255 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Lakshmi
Top achievements
Rank 1
Lakshmi asked on 18 Apr 2016, 09:46 AM

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

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 20 Apr 2016, 08:12 AM
Hello Lakshmi,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
SpaceAnt
Top achievements
Rank 1
answered on 09 May 2016, 12:22 PM

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.}

0
Pavel R. Pavlov
Telerik team
answered on 12 May 2016, 08:26 AM
Hello,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
alisakhi
Top achievements
Rank 1
answered on 23 Oct 2016, 08:06 AM

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.

0
Pavel R. Pavlov
Telerik team
answered on 26 Oct 2016, 06:24 AM
Hi,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Anish
Top achievements
Rank 1
answered on 15 Jun 2018, 11:33 AM

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

0
Didi
Telerik team
answered on 19 Jun 2018, 02:55 PM
Hi,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Divya
Top achievements
Rank 1
answered on 02 May 2019, 10:28 AM

Hi Lakshmi

I think You need to use <telerikChart:RadCartesianChart.ChartBehaviors>  instead of <telerikChart:RadCartesianChart.Behaviors>

Tags
Chart
Asked by
Lakshmi
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
SpaceAnt
Top achievements
Rank 1
alisakhi
Top achievements
Rank 1
Anish
Top achievements
Rank 1
Didi
Telerik team
Divya
Top achievements
Rank 1
Share this question
or