FieryA
FieryA

Reputation: 297

Use of Kendo's Pie chart with dynamic data

i'm trying to use a pie chart to display statistics. Data is within my table and i get it this way:

public class StatisticsAccess
{
    public static object getTypesForStatistics()
    {
        var dbo = new UsersContext();
        var all = (from a in dbo.Note
                      select a).ToList();
        var results = all.GroupBy(item => item.language.lang)
                         .Select(g => new
                         {
                             language = g.Key,
                             Count = g.Select(l => l.language.lang).Count()
                         });
        return (results.ToList());

    }
}

Controller :

public ActionResult Index()
{
    var results = Json(DAL.StatisticsAccess.getTypesForStatistics());
    return View();      
}

View:

  @(Html.Kendo().Chart()
        .Name("chart")
                .Title(title => title
                    .Text("Share of Internet Population Growth, 2007 - 2012")
                    .Position(ChartTitlePosition.Bottom))
        .Legend(legend => legend
            .Visible(false)
        )
        .Series(series => {
            series.Pie(model => model.language, model => model.Count);
        })
        .DataSource(ds => ds.Read(read => read.Action("index", "Statistics")))
        .Tooltip(tooltip => tooltip
            .Visible(true)
            .Format("{0}%")
        )


    )

There are syntax errors in my view, in the series property:

Cannot convert lambda expression to type "string"

Can anyone explain me the syntax i shoud follow to fix this error ? Thx

Upvotes: 1

Views: 989

Answers (1)

JFlox
JFlox

Reputation: 708

I think you are doing the Count in your LINQ the wrong way.

Count = g.Select(l => l.language.lang).Count()

There is no need to do a Select here as they are already group from your .GroupBy

should be:

Count = g.Count()

Using GroupBy, Count and Sum in LINQ Lambda Expressions

Upvotes: 2

Related Questions