I have a total number of experiments, each can be in on of 6 states. I'd like to present this data as a pie chart using XamChart.
How can I bind the number of experiments in state X to a part of the pie? The Feature Browser isn't much help here.
问问题
553 次
2 回答
0
You would need a list that has the states and values for those states and then you would use that as the data source for a series. The following is a simple example using a 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;
}
The DataMapping property is what determines what the values and the Labels are. For this example the XamChart was created in XAML with the following markup:
<igCA:XamChart Name="xamChart1"/>
于 2013-01-08T19:42:33.273 回答
0
What I did was binding the value to the numeric value. To show those numbers in the built-in legend I used the label, but my databinding was to a string that was concatenated like this:
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>
于 2013-02-28T07:49:30.503 回答