如何更改WinRT XAML Toolkit Chart控件的调色板颜色?

Min*_*amy 3 silverlight-toolkit windows-runtime winrt-xaml windows-store-apps winrt-xaml-toolkit

如何在WinRT XAML Toolkit图表控件中更改图表控件的调色板颜色?

例如,我想更改饼图切片的颜色.

Fil*_*kun 8

如果在工具箱的源代码中搜索"Palette",您将看到Chart控件的默认样式如何具有Palette属性的集合ResourceDictionary.您可以在应用程序中以类似的方式将其应用为图表Style或直接作为其属性,例如

<charting:Chart
    x:Name="PieChartWithCustomPalette"
    Title="Pie Chart with Custom Palette"
    Margin="70,0">
    <charting:Chart.Palette>
        <charting:ResourceDictionaryCollection>
            <!-- Blue -->
            <ResourceDictionary>
                <SolidColorBrush
                    x:Key="Background"
                    Color="#4586d8" />
                <Style
                    x:Key="DataPointStyle"
                    TargetType="Control">
                    <Setter
                        Property="Background"
                        Value="{StaticResource Background}" />
                </Style>
                <Style
                    x:Key="DataShapeStyle"
                    TargetType="Shape">
                    <Setter
                        Property="Stroke"
                        Value="{StaticResource Background}" />
                    <Setter
                        Property="StrokeThickness"
                        Value="2" />
                    <Setter
                        Property="StrokeMiterLimit"
                        Value="1" />
                    <Setter
                        Property="Fill"
                        Value="{StaticResource Background}" />
                </Style>
            </ResourceDictionary>
            <!-- Red -->
            <ResourceDictionary>
                <SolidColorBrush
                    x:Key="Background"
                    Color="#dc443f" />
                <Style
                    x:Key="DataPointStyle"
                    TargetType="Control">
                    <Setter
                        Property="Background"
                        Value="{StaticResource Background}" />
                </Style>
                <Style
                    x:Key="DataShapeStyle"
                    TargetType="Shape">
                    <Setter
                        Property="Stroke"
                        Value="{StaticResource Background}" />
                    <Setter
                        Property="StrokeThickness"
                        Value="2" />
                    <Setter
                        Property="StrokeMiterLimit"
                        Value="1" />
                    <Setter
                        Property="Fill"
                        Value="{StaticResource Background}" />
                </Style>
            </ResourceDictionary>
        </charting:ResourceDictionaryCollection>
    </charting:Chart.Palette>
    <charting:Chart.Series>
        <Series:PieSeries
            Title="Population"
            ItemsSource="{Binding Items}"
            IndependentValueBinding="{Binding Name}"
            DependentValueBinding="{Binding Value}"
            IsSelectionEnabled="True" />
    </charting:Chart.Series>
</charting:Chart>
Run Code Online (Sandbox Code Playgroud)

我将此添加到示例项目中以供将来参考.

在此输入图像描述