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

Selected point moves on zoom

1 Answer 91 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Hafsa
Top achievements
Rank 1
Hafsa asked on 22 Apr 2013, 05:53 AM
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! 


1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 23 Apr 2013, 08:10 AM
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.

Tags
ChartView
Asked by
Hafsa
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Share this question
or