c# - 样式化 Wpf 饼图

标签 c# wpf charts wpftoolkit

这是我的饼图 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>

下面是填充数据的代码

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;
}

输出结果如下

Chart

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

enter image description here

最佳答案

我认为您应该能够使用 Color Palette .看看 How to set a default colour to the Pie slices in WPF Pie chart在 StackOverflow 上发帖。

另外,看看 Chart Appearance MSDN 上的文章。

关于c# - 样式化 Wpf 饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18464752/

相关文章:

c# - 使用 C#7 的 foreach 声明中的空合并运算符

c# - 为什么 Microsoft 的这段示例代码会崩溃?

c# - 无法写入输入以处理 C# Mono

javascript - 任何具有 TreeView 、缩放和编辑功能的 jQuery 甘特图?

c# - 突出显示 Asp.net 图表控件系列中的一列

C# FtpWebRequest 设置接口(interface)

c# - 突出显示列表框中的多个项目

wpf - 可以按字母顺序排列 Oxyplot 图表图例中的系列吗?

c# - 在ViewModel中修改后,String属性在View中不会更新

mysql - 如何对不熟悉的行进行分组?