简体   繁体   中英

Styling Wpf Pie Chart

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>

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

图表

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

在此输入图像描述

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM