我有多个实验,每个实验都有6个州。我想使用XamChart将这些数据显示为饼图 如何将状态X中的实验数量绑定到饼图的一部分?功能浏览器在这里没什么帮助。
答案 0 :(得分:0)
您需要一个包含这些状态的状态和值的列表,然后您将其用作系列的数据源。以下是使用DataTable的简单示例:
void Window1_Loaded(object sender, RoutedEventArgs e)
{
Series s = new Series()
{
DataSource = TestData(5).DefaultView,
DataMapping = "Value = Col_3; Label = Col_1",
ChartType = ChartType.Pie,
Label = "Series 1"
};
this.xamChart1.Series.Add(s);
}
private DataTable TestData(int rows)
{
DataTable dtData = new DataTable("TestData");
dtData.Columns.Add("Col_1", typeof(string));
dtData.Columns.Add("Col_3", typeof(int));
for (int i = 1; i <= rows; i++)
{
DataRow dr = dtData.NewRow();
dr["Col_1"] = "Row " + i.ToString();
dr["Col_3"] = i;
dtData.Rows.Add(dr);
}
return dtData;
}
DataMapping属性决定了值和标签的含义。对于此示例,XamChart是在XAML中使用以下标记创建的:
<igCA:XamChart Name="xamChart1"/>
答案 1 :(得分:0)
我所做的是将值绑定到数值。为了在内置图例中显示这些数字,我使用了标签,但我的数据绑定是一个串联的字符串,如下所示:
string RuningLabel = `"Running, " + NumRunning`;
XAML:
<igCa:XamChart.Series>
<igCa:Series ChartType="Pie">
<igCa:Series.DataPoints>
<igCa:DataPoint Value="{Binding ActivityStatus.NumWaiting}" Label="{Binding Path=InfoHelper.WaitingLabel}" Fill="Yellow"/>
<igCa:DataPoint Value="{Binding ActivityStatus.NumAssigned}" Label="{Binding Path=InfoHelper.AssignedLabel}" Fill="LightPink"/>
<igCa:DataPoint Value="{Binding ActivityStatus.NumRunning}" Label="{Binding InfoHelper.RunningLabel}" Fill="Orange"/>
<igCa:DataPoint Value="{Binding ActivityStatus.NumPassed}" Label="{Binding InfoHelper.PassedLabel}" Fill="Green"/>
<igCa:DataPoint Value="{Binding ActivityStatus.NumFailed}" Label="{Binding Path=InfoHelper.FailedLabel}" Fill="DarkRed"/>
<igCa:DataPoint Value="{Binding ActivityStatus.NumOnHold}" Label="{Binding InfoHelper.OnholdLabel}" Fill="DarkGray"/>
<igCa:DataPoint Value="{Binding ActivityStatus.NumRemoved}" Label="{Binding InfoHelper.RemovedLabel}" Fill="LightBlue"/>
<igCa:DataPoint Value="{Binding ActivityStatus.NumStopped}" Label="{Binding InfoHelper.StoppedLabel}" Fill="CornflowerBlue"/>
<igCa:DataPoint Value="{Binding ActivityStatus.NumStuck}" Label="{Binding InfoHelper.StuckLabel}" Fill="DarkKhaki"/>
</igCa:Series.DataPoints>
</igCa:Series>
</igCa:XamChart.Series>