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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Retrieve the Index of the Segmet Selected

Thread ID:

Created:

Updated:

Platform:

Replies:

115975 Mar 10,2014 10:25 AM UTC Apr 4,2014 01:33 PM UTC Windows Phone 5
loading
Tags: Chart
ahmad0101
Asked On March 10, 2014 10:25 AM UTC

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

Karthikeyan V [Syncfusion]
Replied On 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.


ahmad0101
Replied On 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

Karthikeyan V [Syncfusion]
Replied On 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.


ahmad0101
Replied On 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

Suresh S [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;