chart selection behaviour is not working

6 posts, 0 answers
  1. Lakshmi
    Lakshmi avatar
    11 posts
    Member since:
    Nov 2014

    Posted 18 Apr Link to this post

    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.

  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 20 Apr Link to this post

    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
  3. DevCraft banner
  4. SpaceAnt
    SpaceAnt avatar
    2 posts
    Member since:
    Apr 2016

    Posted 09 May Link to this post

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

  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 12 May Link to this post

    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
  6. alisakhi
    alisakhi avatar
    3 posts
    Member since:
    Jan 2014

    Posted 23 Oct Link to this post

    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.

  7. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 26 Oct Link to this post

    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
Back to Top
DevCraft banner