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

When users tap on a data point on RadCartesianChart, how do I get a reference to the object bound to this data?

1 Answer 15 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alex
Top achievements
Rank 1
Alex asked on 19 Jul 2014, 10:41 PM
When users tap on a data point on a RangeBarSeries, I would like to get a reference to the bound object, so that I can trigger my custom logic (ex. take the user to the details page of this object).

By subscribing to the Tap event of the RadCartesianChart, I can detect when users tap on a range and get coordinates of the tap, but missing the part of how to get from the coordinates to the bound object.

Thanks
Alex.

private void HeartRateZoneChart_OnTap(object sender, GestureEventArgs e)
        {
            var chart = (RadCartesianChart)sender;
            Debug.WriteLine("Tap");
            Debug.WriteLine(e.GetPosition(HorizontalAxis));
        }


<telerikChart:RadCartesianChart x:Name="HeartRateZoneChart" Tap="HeartRateZoneChart_OnTap">
            .....            
            <telerikChart:RangeBarSeries CategoryBinding="Name"
                                         Canvas.ZIndex="2"
                                         HighBinding="High"
                                         LowBinding="Low">
                <telerikChart:RangeBarSeries.PointTemplate>
                    <DataTemplate>
                        <Grid Background="{StaticResource PhoneForegroundBrush}">
                            <Canvas VerticalAlignment="Top">
                                <TextBlock 
                                    Text="{Binding Path=High}"
                                    Canvas.Left="10"
                                    Canvas.Top="-28"
                                    Foreground="{StaticResource AnnotationsPointForeground}"/>
                            </Canvas>

                            <Canvas VerticalAlignment="Bottom">
                                <TextBlock 
                                    Text="{Binding Path=Low}"
                                    Canvas.Left="7"/>
                            </Canvas>
                        </Grid>
                    </DataTemplate>
                </telerikChart:RangeBarSeries.PointTemplate>
            </telerikChart:RangeBarSeries>
        </telerikChart:RadCartesianChart>
    </Grid>





1 Answer, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 20 Jul 2014, 10:20 PM
I was missing the part that I needed to cast the Series object to the RangeBarSeries, which exposed the DataPoints collection. Consequently, through the DataPoints collection I can find the member of that collection with the IsSelected property set to true, and from there get to the DataItem, which what I was after.
I hope this helps somebody in the future.

private void HeartRateZoneChart_OnTap(object sender, GestureEventArgs e)
        {
            Debug.WriteLine("Tap Event Fired");
            var chart = (RadCartesianChart)sender;
            var series = (RangeBarSeries)chart.Series[0];
            var dataPoints = series.DataPoints;
            
            foreach (var rangeDataPoint in dataPoints)
            {
                if (rangeDataPoint.IsSelected)
                {
                    var selectedHeartRateZone = (HeartRateZone)rangeDataPoint.DataItem;
                    Debug.WriteLine(selectedHeartRateZone.Name);
                    break;
                }
            }
        }
Tags
Chart
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Share this question
or