这是我到目前为止的代码,基本上它获取了uniqueid的实际值,并将其用作每个系列的值:
string[] XPointMember = new string[table.Rows.Count];
int[] YPointMember = new int[table.Rows.Count];
for (int count = 0; count < table.Rows.Count; count++)
{
XPointMember[count] = table.Rows[count]["GuitarBrand"].ToString();
YPointMember[count] = Convert.ToInt32(table.Rows[count]["UniqueID"]);
}
//binding chart control
chart1.Series[0].Points.DataBindXY(XPointMember, YPointMember);
我想要完成的是添加该吉他品牌的每个实例的数量以显示为价值。因此,如果特定GuitarBrand有4个实例,则该值应为4。
谢谢!
答案 0 :(得分:1)
这应该这样做:
//First populate the X axis only (the series)
for (int index = 0; index < table.Rows.Count; index++)
{
XPointMember[index] = table.Rows[index]["GuitarBrand"].ToString();
}
//Loop again, and for each series, use the Count method
//to see how much occurrences of the same guitar brand are there
for (int index = 0; index < table.Rows.Count; index++)
{
var guitar_brand = XPointMember[index];
YPointMember[index] = XPointMember.Count(x => x == guitar_brand);
}
请注意,我使用index
代替count
作为循环变量。在这里使用count
会让代码的读者感到困惑。