称呼Wpf饼图 [英] Styling Wpf Pie Chart

查看:229
本文介绍了称呼Wpf饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我饼图的xaml。

Here is my xaml for the pie chart.

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

输出如下

我改变图表的各个段的背景颜色。类似下面的图表。

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

推荐答案

我认为您应该可以使用调色板。请查看如何设置默认颜色到饼图在WPF饼图在这里StackOverflow。

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 chart post here on StackOverflow.

此外,看看图表外观文章在MSDN上。

Additionally, take a look at the Chart Appearance article on MSDN.

这篇关于称呼Wpf饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆