- Home
- Forum
- Windows Phone
- Retrieve the Index of the Segmet Selected
Retrieve the Index of the Segmet Selected
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
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.
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
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.
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
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
- 5 Replies
- 3 Participants
-
AH ahmad0101
- Mar 10, 2014 10:25 AM UTC
- Apr 4, 2014 01:33 PM UTC