C# 图表绑定到 var

发布于 2024-12-17 00:02:28 字数 532 浏览 3 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素年丶 2024-12-24 00:02:28

我从未使用过 ASP.Net 图表,所以我不确定这是否有效,但我认为它应该:

series1.Points.DataBindXY(t.Select(x => x.Type), t.Select(x => x.Count));

这会将 Type 值的集合指定为 x 值和 的集合>将值计算为 y 值。

I have never worked with ASP.Net charts, so I'm not sure this will work, but I think it should:

series1.Points.DataBindXY(t.Select(x => x.Type), t.Select(x => x.Count));

This will assign a collection of Type values as the x values and collection of Count values as y values.

极致的悲 2024-12-24 00:02:28
var t= (from oAction in Actions
                    group oAction by oAction.Type.Name into g
                    select new { Type = g.Key, Count = g.Count() }).ToArray();

好的,所以您将返回“匿名”类型。您绝对可以访问 t.Type 或 t.Count,但问题是您只能在定义此 LINQ 查询的方法内执行此操作。匿名类型的范围仅限于定义它的方法。您可以通过使用“dynamic”关键字来克服此限制。但我还没有尝试过,所以不能100%确定。

var t= (from oAction in Actions
                    group oAction by oAction.Type.Name into g
                    select new { Type = g.Key, Count = g.Count() }).ToArray();

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文