Таблица Syncfusion для Windows Phone 8

У меня есть круговая диаграмма, и я хочу взорваться и сделать другие вещи, когда кусок пирога установлен. Итак, мой вопрос: как я могу получить индекс, выбранный в коде

Вот мой XAML

        <chart:SfChart.PrimaryAxis>
            <chart:CategoryAxis></chart:CategoryAxis>
        </chart:SfChart.PrimaryAxis>
        <chart:SfChart.SecondaryAxis>
            <chart:NumericalAxis></chart:NumericalAxis>
        </chart:SfChart.SecondaryAxis>

        <chart:PieSeries  PieCoefficient="0.6" MouseLeftButtonDown="pieSeries_MouseLeftButtonDown" ExplodeRadius="20"  EnableAnimation="True" x:Name="pieSeries" ShowTooltip="True" chart:ChartTooltip.EnableAnimation="True" ItemsSource="{Binding Expenditure}" XBindingPath="Expense" Label="" LabelPosition="Outside" YBindingPath="Amount"  Palette="Custom">
            <chart:PieSeries.ColorModel>

                <chart:ChartColorModel>

                    <chart:ChartColorModel.CustomBrushes>

                        <SolidColorBrush Color="Green"/>

                        <SolidColorBrush Color="Black"/>

                        <SolidColorBrush Color="Red"/>

                        <SolidColorBrush Color="#FFD541"/>

                        <SolidColorBrush Color="Plum"/>

                        <SolidColorBrush Color="Purple"/>

                    </chart:ChartColorModel.CustomBrushes>

                </chart:ChartColorModel>

            </chart:PieSeries.ColorModel>
            <chart:PieSeries.AdornmentsInfo>
                <chart:ChartAdornmentInfo AdornmentsPosition="Bottom"  HorizontalAlignment="Center" VerticalAlignment="Center" 
                                              ConnectorLineStyle="{StaticResource lineStyle}" ShowConnectorLine="True" 
                                              ConnectorHeight="30" ShowLabel="True"  LabelTemplate="{StaticResource labelTemplate}" 
                                              SegmentLabelContent="YValue">
                </chart:ChartAdornmentInfo>
            </chart:PieSeries.AdornmentsInfo>

        </chart:PieSeries>
    </chart:SfChart>
 In the c# code I want The MouseLeftButtonDown Event to trigger the slice of the pie to explode 

 private void pieSeries_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {

}

person user3401676    schedule 10.03.2014    source источник
comment
Добро пожаловать в Stackoverflow, вы хотите добавить код в свой пост, мы хотели бы увидеть, что вы уже пробовали.   -  person MCollard    schedule 10.03.2014


Ответы (1)


Вместо того, чтобы пытаться использовать события Mouse, Syncfusion предоставил SelectionBehavior, который может быть полезен для последовательного выбора сегментов. Также к этим внутренним сегментам можно получить доступ, создав пользовательскую серию, наследующую Pie Series, как показано ниже.

public class CustomPieSeries : PieSeries
{
    public ObservableCollection<ChartSegment> PieSegments { get; set; }
    public override void CreateSegments()
    {
        base.CreateSegments();
        PieSegments = Segments;
    }
}

<local:CustomPieSeries SegmentSelectionBrush="Cornsilk" ItemsSource="{Binding Expenditure}" XBindingPath="Expense" YBindingPath="Amount"   EnableAnimation="True" PieCoefficient="0.6"  ExplodeRadius="20"   x:Name="pieSeries" ShowTooltip="True" chart:ChartTooltip.EnableAnimation="True"  Label="" LabelPosition="Outside"   Palette="Custom">
            <local:CustomPieSeries.ColorModel>

                <chart:ChartColorModel>

. . . Затем добавьте событие SelectionChanged для диаграммы, чтобы получить индекс выбранного сегмента, как показано ниже.

private void SfChart_SelectionChanged_1(object sender, Syncfusion.UI.Xaml.Charts.ChartSelectionChangedEventArgs e)
    {
        int selectedSegmentIndex = (chart.Series[0] as CustomPieSeries).PieSegments.IndexOf(e.SelectedSegment);
    }
person user3595561    schedule 02.05.2014