【问题标题】:How to change the palette colors of WinRT XAML Toolkit Chart controls?如何更改 WinRT XAML Toolkit Chart 控件的调色板颜色?
【发布时间】:2013-02-04 14:39:59
【问题描述】:

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

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

【问题讨论】:

    标签: windows-runtime windows-store-apps winrt-xaml silverlight-toolkit winrt-xaml-toolkit


    【解决方案1】:

    如果您在工具包的源代码中搜索“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>
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 2023-04-08
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多