C# 图表绑定到 var
我有 var t 来自 linq 查询,具有以下结构:
[0] = { Type = "K", Count = 1 }
[1] = { Type = "Z", Count = 8 }
现在我想将它优雅地绑定到我的图表(没有 foreach)。我尝试做这样的事情:
series1.Points.DataBindXY(t. ????, t.????);
但我不知道如何获取我的变量的“第一列”和“第二列”。 请帮忙
编辑: 我的 linq 查询:
var t= (from oAction in Actions
group oAction by oAction.Type.Name into g
select new { Type = g.Key, Count = g.Count() }).ToArray();
I have var t from linq query with this structure:
[0] = { Type = "K", Count = 1 }
[1] = { Type = "Z", Count = 8 }
and now I want to bind it to my chart with elegance (no foreach). I try to do something like this:
series1.Points.DataBindXY(t. ????, t.????);
but I don't know how to get "first column" and "second column" of my var.
Please help
Edit:
My linq query:
var t= (from oAction in Actions
group oAction by oAction.Type.Name into g
select new { Type = g.Key, Count = g.Count() }).ToArray();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未使用过 ASP.Net 图表,所以我不确定这是否有效,但我认为它应该:
这会将
Type
值的集合指定为 x 值和的集合>将
值计算为 y 值。I have never worked with ASP.Net charts, so I'm not sure this will work, but I think it should:
This will assign a collection of
Type
values as the x values and collection ofCount
values as y values.好的,所以您将返回“匿名”类型。您绝对可以访问 t.Type 或 t.Count,但问题是您只能在定义此 LINQ 查询的方法内执行此操作。匿名类型的范围仅限于定义它的方法。您可以通过使用“dynamic”关键字来克服此限制。但我还没有尝试过,所以不能100%确定。
All-right, so you are returning an "Anonymous" type. You can definitely access t.Type or t.Count but the catch is you can do this only inside the method where this LINQ query is defined. The scope of anonymous type is limited to the method in which it is defined. You can overcome this limitation by using "dynamic" keyword. But I haven't tried this, so can't be 100% sure.