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. Image for the cookie policy date

SelectedSegment set to null when SelectionChanged is triggered on a point in a SplineAreaSeries

I'm using a SplineAreaSeries and have set an event handler to catch a data point change: 
chart.SelectionChanged += chart_SelectionChanged

The aim of this call is to show a bespoke tooltip. Unfortunately when the event is triggered, ((SfChart.SelectionChangedEventArgs) e).P1.SelectedSegment is set to null and therefore I can't access its X1 and Y1 properties to determine where to place the tooltip (e.P1 is otherwise populated correctly/as expected). This isn't an issue when working with a SplineSeries.

Any guidance is most appreciated.

3 Replies

BK Bharathiraja K Syncfusion Team February 28, 2019 08:58 AM UTC

Hi Bardi, 
Greetings from Syncfusion. We have analyzed your query and we would like to let you know that the Line and Spline series type will draw path for each segment and the SelectedSegment value will return the segment value. But for the Area series type like SplineAreaSeries or AreaSeries the path will draw for the entire chart area. Due to this reason SelectedSegment value will return null for the SplineAreaSeries.  
We can achieve your requirement to get the X1 and Y1 position of the selected segment as a workaround by using the SelectedDataPointIndex and the chart ValueToPoint() method of the ChartAxis to get the screen position of the selected segment. 
Please refer the below code snippet. 
Code Snippet [C#]: 
private void Chart_SelectionChanged(object sender, SfChart.SelectionChangedEventArgs e) 
      var currentIndex = e.P1.SelectedDataPointIndex; 
      var items = e.P1.SelectedSeries.ItemsSource; 
      var data = items as ObservableCollection<Model1>; 
      if (data != null) 
           var yVal = data[currentIndex].YValue; 
           var xVal = data[currentIndex].XValue; 
           var X1 = e.P0.PrimaryAxis.ValueToPoint(xVal); //Here can get the X1 value 
           var Y1 = e.P0.SecondaryAxis.ValueToPoint(yVal); //Here can get the Y1 value 
Please refer the below ug document for more details 
Use the ValueToPoint(axis,value) method available in SfChart to convert the screen point for the chart area and the ValueToPoint(value) method available in ChartAxis, to convert the screen point within the rendered area of the series. 
We have prepared a sample for your requirement and you can download the sample form the below link. 

BG Bardi Golriz February 28, 2019 10:38 AM UTC

Brilliant, thanks!

BK Bharathiraja K Syncfusion Team March 1, 2019 07:11 AM UTC

Hi Bardi, 
We are glad that the provided solution resolved your requirement. Please let us know if you have any other queries. 

Live Chat Icon For mobile
Up arrow icon