We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to navigate to other page with data point information of selected data in Xamarin.Forms Chart?

Platform: Xamarin.Forms |
Control: SfChart |
Published Date: April 16, 2018 |
Last Revised Date: August 21, 2019

Chart provides selection support for data points on touch or by using SelectedDataPointIndex property of ChartSeries to programmatically select a data pooint. You can enable the selection behavior for any series using EnableDataPointSelection property. Chart’s SelectionChanged event will notify to the user when selection changed. This event contains selected index, previous selected index and selected series. Please refer the below code snippets to enable data point selection, hooking the SelectionChanged event and navigating to another page with the selected data point information when selection changed.

 

Code snippets for enabling data point selection:

 

Xaml

 

<chart:PieSeries EnableDataPointSelection="True" />

 

C#

 

pieSeries.EnableDataPointSelection = true;

                       

Code snippets to hook SelectionChanged event:

 

Xaml

 

<chart:SfChart SelectionChanged="Chart_SelectionChanged">
    . . .
</chart:SfChart>

 

C#

 

chart.SelectionChanged += Chart_SelectionChanged;

 

Code snippet to navigate to other page with the information of selected data point:

 

C#

 

private void Chart_SelectionChanged(object sender, ChartSelectionEventArgs e)
{
    if (e.SelectedDataPointIndex > -1)
    {
        var data = e.SelectedSeries.ItemsSource as ObservableCollection<Model>;
        Navigation.PushAsync(new TextPage() { Item = data[e.SelectedDataPointIndex] });
    }
}

 

By default, selected segment is highlighted with a color. You can stop applying the selected segment color by cancelling the selection before navigating to other page in SelectionChanging event. Please refer the below code snippet.

 

C#

 

private void chart_SelectionChanging(object sender, ChartSelectionChangingEventArgs e)
{
    if (e.SelectedDataPointIndex > -1)
    {
        var data = e.SelectedSeries.ItemsSource as ObservableCollection<Model>;
        Navigation.PushAsync(new TextPage() { Item = data[e.SelectedDataPointIndex] });
    }
    e.Cancel = true;
}

 

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
asolute dev
Oct 11, 2018

Can u help me I follow the step but the selected data point index still remain 0.

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon