Selected point moves on zoom

2 posts, 0 answers
  1. Hafsa
    Hafsa avatar
    8 posts
    Member since:
    Mar 2013

    Posted 22 Apr 2013 Link to this post

    Hi,

    When zooming into a chart and selecting a point, the selection seems to move along with the scroll bars. I noticed this while adding an annotation feature in my project, and used the selection example from your documentation to test it.
     
      <telerik:RadCartesianChart.Behaviors>
          <telerik:ChartSelectionBehavior DataPointSelectionMode="Single" SelectionChanged="ChartSelectionBehavior_SelectionChanged_1" />
          <telerik:ChartPanAndZoomBehavior ZoomMode="Both" PanMode="Both"/>
      </telerik:RadCartesianChart.Behaviors>
    private void ChartSelectionBehavior_SelectionChanged_1(object sender, ChartSelectionChangedEventArgs e)
            {
                //Handle selection of the current point
                if (e.AddedPoints.Count > 0)
                {
                    var addedPoint = e.AddedPoints[0];
                    var series = addedPoint.Presenter as LineSeries;
     
                    //Get the Content Presenter of the series
                    var pointPresenter = series.ChildrenOfType<ContentPresenter>().
                        Where(cp => cp.Tag == addedPoint).FirstOrDefault();
                    var ellipseElement = pointPresenter.
                        ChildrenOfType<Ellipse>().FirstOrDefault();
     
                    //Do whatever you want with it :)
                    ellipseElement.Fill = new SolidColorBrush(Colors.Red);
                }
     
                //Handle de-selection of the current point
                if (e.RemovedPoints.Count > 0)
                {
                    var removedPoint = e.RemovedPoints[0];
                    var series = removedPoint.Presenter as LineSeries;
                    var pointPresenter = series.
                        ChildrenOfType<ContentPresenter>().
                        Where(cp => cp.Tag == removedPoint).FirstOrDefault();
                    var ellipseElement = pointPresenter.
                        ChildrenOfType<Ellipse>().FirstOrDefault();
     
                    //Do whatever you want with it :)
                    ellipseElement.Fill = new SolidColorBrush(Colors.Yellow);
                }
     
            }

    I've attached a couple of screenshots to make it clearer. The selected point shouldn't move - do you know why this is happening?

    Thanks! 


  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 23 Apr 2013 Link to this post

    Hello,

    This is not a bug in the ChartView. For performance considerations when the chart is redrawn (on zoom in, or data rebind) it reuses the already created ContentPresenters (the ellipses). So when you pan the chart - the second ellipse is reused. You have already updated its Fill to Red and after the items source changes - it is still Red.

    To work around this you can use a Binding. I suggest you create a new IsSelected property in your ChartData class. The class should implement the INotifyPropertyChanged interface in order for the Binding to kick in correctly. I also suggest that you do not use the chart's selection behavior as it would be easier to manually manipulate this new property in code. An update for the PointTemplate is also necessary. I have attached a sample project I have from a previous ticket to demonstrate the suggestions.

    Let us know if we can be of further help.

    Regards,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top