Data Point Selection Event

I use the selection changed event but the selected data point index keep remain 0. I uploaded the code screen shot please tell me if i going the wrong direction.
 

Attachment: code_d7e59d18.zip

3 Replies

MP Michael Prabhu M Syncfusion Team October 11, 2018 10:26 AM UTC

Hi Wei Chun, 

We have achieved this requirement with the help of SelectionChanging Event in Chart. Please refer the below code snippets to enable data point selection, hooking the SelectionChanging event and navigating to another page with the selected data point information when selection changing. 

<StackLayout Padding="0,20,0,0"> 
 
        <local:ChartExt x:Name="chart" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" SelectionChanging="Chart_SelectionChanging"> 
 
            <chart:SfChart.PrimaryAxis> 
                <chart:CategoryAxis/> 
            </chart:SfChart.PrimaryAxis> 
 
            <chart:SfChart.Legend> 
                <chart:ChartLegend/> 
            </chart:SfChart.Legend> 
 
            <chart:SfChart.SecondaryAxis> 
                <chart:NumericalAxis/> 
            </chart:SfChart.SecondaryAxis> 
 
        </local:ChartExt> 
    </StackLayout> 



pieSeries = new PieSeries 
{ 
       EnableDataPointSelection = true, 
       SelectedDataPointColor = Color.Pink, 
       ExplodeOnTouch = true, 
       XBindingPath = "Name", 
       YBindingPath = "Value", 
       Label = "PieSeries", 
       ItemsSource = view.PieData, 
       DataMarker = new ChartDataMarker() 
}; 
 
      pieSeries.ColorModel.Palette = ChartColorPalette.Natural; 
      chart.Series.Add(pieSeries); 
 
async void Chart_SelectionChanging(object sender, ChartSelectionChangingEventArgs e) 
{ 
     if (e.SelectedDataPointIndex > -1) 
     { 
           IList items = e.SelectedSeries.ItemsSource as IList; 
           Model selectedDatapoint = items[e.SelectedDataPointIndex] as Model; 
           await Navigation.PushModalAsync(new SecondaryPage(selectedDatapoint)); 
     } 
} 



We have prepared a simple sample and it can be downloaded from the link below. 


Also, there is Knowledge Base article you can refer on this. 


Thanks, 
Michael 




AD asolute dev October 12, 2018 01:16 AM UTC

Thanks for the help, I just realized  I used  ChartSelectionChangingEvent instead of  ChartSelectionChangingEventArgs, now everything work fine. Thanks for the support.


MP Michael Prabhu M Syncfusion Team October 12, 2018 04:17 AM UTC

Hi Wei Chun, 
 
Glad! we could help. Feel free to contact us anytime if you need any other assistance from us. We are happy to help you.   
  
Thanks,  
Michael  



Loader.
Up arrow icon