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

Retrieve the Index of the Segmet Selected

Hy ,
I have a Pie chart and i want to explode and to Other things when a slice of the Pie is setected
So my question is How can i retrieve the Index selected

5 Replies

KV Karthikeyan V Syncfusion Team March 12, 2014 05:37 AM UTC

Hi Ahmad,

Thanks for using the Syncfusion products.

We have analysed the reported requirement. You can able to achieve this requirement with help of selection changed event in sfchart.

Code snippet [XAML]:

<chart:SfChart SelectionChanged="SfChart_SelectionChanged" >

<chart:SfChart.Behaviors>

       <chart:ChartSelectionBehavior />

</chart:SfChart.Behaviors>

Code snippet [C#]:

private void SfChart_SelectionChanged(object sender, ChartSelectionChangedEventArgs e)

        {

            var seg = (e.SelectedSegment) as ChartSegment;

            ChartSeriesBase series = seg.Series;

            var b = series.GetType().GetRuntimeFields();

            ObservableCollection<ChartSegment> Segments = new ObservableCollection<ChartSegment>();

            foreach (var item in b)

            {

              if (item.Name == "Segments")

              {

                Segments = (ObservableCollection<ChartSegment>)item.GetValue(series);

              }

            }

            int i = 0;

            foreach (var item in Segments)

            {

                if (item == seg)

                    break;

                i++;

            }

            (e.SelectedSeries as AccumulationSeriesBase).ExplodeIndex = i;

        }

Please let us know if you require further assistance on this.

Thanks,

Karthikeyan V.



AH ahmad0101 March 12, 2014 10:16 PM UTC

Thanks the code its works fine but I had to change
the var b = series.GetType().GetRuntimeFields();
to   FieldInfo[] b = series.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);

but When i Click on the same Slice for the Second time it selected Again and the Color Go to Value defined in SegmentSelectionBrush
is there a way to prevent the selected change if the i clicked on the same slice


KV Karthikeyan V Syncfusion Team March 17, 2014 07:00 AM UTC

Hi Ahmad,

Thanks for the update.

We have analysed the reported query. We have suggested better solution for without using the reflector, also for this solution segment selection brush not applies. Please find the code snippet in below.

Code snippet [C#]:

        private void SfChart_SelectionChanged_1(object sender, ChartSelectionChangedEventArgs e)

        {

           seg = (e.SelectedSegment) as ChartSegment;

           ChartSeriesBase series = seg.Series;

           int b1 = (series.ItemsSource as ObservableCollection<power>).IndexOf(seg.Item as power);

           if ((e.SelectedSeries as PieSeries).ExplodeIndex == b1 )

               (e.SelectedSeries as PieSeries).Palette = ChartColorPalette.Metro;

           else

               (e.SelectedSeries as PieSeries).ExplodeIndex = b1;

        }

Please let us know if you require further assistance on this.

Thanks,

Karthikeyan V.



AH ahmad0101 April 2, 2014 11:15 PM UTC

Thanks

an other Question

is there a way to select a default Segmet  in the ColumnSeries
for exemple when the chart is Loaded the last segment is already selected


SS Suresh S Syncfusion Team April 4, 2014 01:33 PM UTC

Hi Ahmad,

Thank you for your patience,

We have analyzed the requirement and currently we don’t have a support for default segment selection at load time, however we have achieved this requirement in work around manner, please find the sample in the below location,

Please let us know if you have any further assistant.

Thanks.

Suresh S.


Attachment: ColumnChart_f6206fe1.zip

Loader.
Live Chat Icon For mobile
Up arrow icon