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

2 posts, 0 answers
  1. Alex
    Alex avatar
    14 posts
    Member since:
    Nov 2013

    Posted 19 Jul 2014 Link to this post

    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>





  2. Alex
    Alex avatar
    14 posts
    Member since:
    Nov 2013

    Posted 20 Jul 2014 in reply to Alex Link to this post

    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;
                    }
                }
            }
  3. DevCraft banner
Back to Top