样式 Wpf 饼图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18464752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:30:47  来源:igfitidea点击:

Styling Wpf Pie Chart

c#wpfchartswpftoolkit

提问by Redone

Here is my xaml for the pie chart.

这是我用于饼图的 xaml。

<chartingToolkit:Chart  Name="pieChart" Title="Top Products" Margin="10,10,0,0" Height="262" BorderBrush="#00000000" DataContext="{Binding}" IsHitTestVisible="False" IsTabStop="True" ForceCursor="True">
        <chartingToolkit:PieSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True" />

            <!-- Plot area-->
            <chartingToolkit:Chart.PlotAreaStyle>
                <Style TargetType="Grid">
                    <Setter Property="Background" Value="White" />
                </Style>
            </chartingToolkit:Chart.PlotAreaStyle>
</chartingToolkit:Chart>

And Here is the code for filling the data

这是填充数据的代码

public void GenerateChart()
{
    List<KeyValuePair<string, double>> valueList = new List<KeyValuePair<string, double>>();
    valueList.Add(new KeyValuePair<string, double>("Apple", 101));
    valueList.Add(new KeyValuePair<string, double>("Banana", 201));
    valueList.Add(new KeyValuePair<string, double>("Cake", 20));
    valueList.Add(new KeyValuePair<string, double>("Others", 200));      

    pieChart.Title = "Top Products";
    pieChart.DataContext = valueList;
}

And the output is as follows

输出如下

Chart

图表

Now how do i change the background color of various segments of the chart. Similar to below chart.

现在我如何更改图表各个部分的背景颜色。类似于下图。

enter image description here

在此处输入图片说明

采纳答案by Sheridan

I think that you should be able to use a Color Palette. Take a look at the How to set a default colour to the Pie slices in WPF Pie chartpost here on StackOverflow.

我认为您应该能够使用Color Palette。在 StackOverflow 上查看如何为 WPF 饼图中的饼图切片设置默认颜色

Additionally, take a look at the Chart Appearancearticle on MSDN.

此外,请查看MSDN上的Chart Appearance文章。