0

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();
Sparkzi
  • 83
  • 1
  • 6
  • Why you do not want foreach loop? You are having a collection. Either your control should be smart enough to pick up right parameter ot you will have to enumerate over the collection. – Pawan Mishra Nov 19 '11 at 15:54
  • Thank you for answer. Can I make easily an array or list with only "first column" of my var (Type only)? – Sparkzi Nov 19 '11 at 16:06
  • Yes you can. Can you post your LINQ query? Basically wanted to see if your LINQ query is returning anonymous type? And "Var" is an implicit type variable and it is compile time evaluated. You can easily see the actual type of the returned value of your query. – Pawan Mishra Nov 19 '11 at 16:12
  • I have edited my question, adding linq. If I get an array of string with Type and array od int with Count it would be very usefull – Sparkzi Nov 19 '11 at 16:22

2 Answers2

0

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.

svick
  • 236,525
  • 50
  • 385
  • 514
0
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.

Pawan Mishra
  • 7,212
  • 5
  • 29
  • 39