我如何使用amcharting对饼图的各个切片进行着色
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<chart:PieChart Height="300" Width="400"
TitleMemberPath="Title"
ValueMemberPath="Value">
<chart:PieChart.DataSource>
<local:PieDataCollection>
<local:PieData Title="Democrat" Value="123"/>
<local:PieData Title="Republic" Value="213"/>
<local:PieData Title="independent" Value="123"/>
</local:PieDataCollection>
</chart:PieChart.DataSource>
</chart:PieChart>
</Grid>
最佳答案
在Windows Phone 8.0和8.0 SDK上进行了测试。
只需将画笔集合添加到PieChart结构中即可。
使用XAML
<chart:PieChart Height="300" Width="400" TitleMemberPath="Title" ValueMemberPath="Value">
<chart:PieChart.Brushes>
<SolidColorBrush Color="Red"/> <!-- color item #1 -->
<SolidColorBrush Color="Green"/> <!-- color item #2 -->
<SolidColorBrush Color="Blue"/> <!-- color item #3 -->
</chart:PieChart.Brushes>
<chart:PieChart.DataSource>
<local:PieDataCollection>
<local:PieData Title="Democrat" Value="123"/>
<local:PieData Title="Republic" Value="213"/>
<local:PieData Title="independent" Value="123"/>
</local:PieDataCollection>
</chart:PieChart.DataSource>
</chart:PieChart>
使用C#
public void LoadColors()
{
System.Windows.Media.SolidColorBrush red = new System.Windows.Media.SolidColorBrush();
red.Color = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00);
System.Windows.Media.SolidColorBrush green = new System.Windows.Media.SolidColorBrush();
green.Color = Color.FromArgb(0xFF, 0x00, 0xFF, 0x00);
System.Windows.Media.SolidColorBrush blue = new System.Windows.Media.SolidColorBrush();
blue.Color = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF);
this.PieChart.Brushes.Add(red); // add red
this.PieChart.Brushes.Add(green); // add green
this.PieChart.Brushes.Add(blue); // add blue
this.PieChart.DataSource = Data; // set the datasource
}
关于c# - 如何给amchart piechart切片上色?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18714852/