使用每个系列意向的计数作为 Y 值
本文关键字:个系列 | 更新日期: 2023-09-27 18:30:23
这是我
到目前为止的代码,基本上它获取了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);
我试图完成的是将该吉他品牌的每个实例的计数添加为值。因此,如果特定吉他品牌有 4 个实例,则值应为 4。
谢谢!
这应该可以做到:
//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
会使代码的读者感到困惑。