日期:2014-05-20 浏览次数:21587 次
/// <summary>
/// 饼状图
/// </summary>
private void UpdateCharts()
{
List<NameValueItem> items = new List<NameValueItem>();
NameValueItem nv = new NameValueItem();
nv.Value = Convert.ToInt32(20);
nv.Name = nv.Value.ToString() + "% 及格比例";
NameValueItem nv1 = new NameValueItem();
nv1.Value = Convert.ToInt32(100 - Convert.ToInt32(20));
nv1.Name = nv1.Value.ToString() + "% 不及格比例";
items.Add(nv);
items.Add(nv1);
((PieSeries)this.PieChart.Series[0]).ItemsSource = items;
}
public class NameValueItem
{
public string Name { get; set; }
public int Value { get; set; }
}
<Charting:Chart
Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Left"
Width="500"
x:Name="PieChart"
Title="" Foreground="Black" FontSize="12">
<Charting:Chart.Series>
<Series:PieSeries
Title="Population"
ItemsSource="{Binding Items}"
IndependentValueBinding="{Binding Name}"
DependentValueBinding="{Binding Value}"
IsSelectionEnabled="True"/>
</Charting:Chart.Series>
</Charting:Chart>