0

I'm having an issue with Telerik's Kendo UI Pie Chart in MVC. I can't find any decent code examples on their site. The one demo I've found only shows half of the code, so I tried guessing at how to get it working. I'm getting an error, and no matter what I've tried to eliminate the error, nothing seems to work. It's having an issue with the series.Pie section where you actually bind the data. I copied the code that was in their example, and used the lambda expression just like they did. model => model.Percentage and model => model.StatusName to work with my view model. But it errors out on the very first lambda, with this error message:

CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type

Here is the relevant code:

ViewModel / View:

public class StatusPercentageViewModel
{
    public string StatusName { get; set; }
    public int Count { get; set; }
    public double Percentage { get; set; }
}


@model IEnumerable<StatusPercentageViewModel>
@(Html.Kendo().Chart(Model)
    .Name("StatusBreakdown")
    .Legend(legend => legend
        .Position(ChartLegendPosition.Bottom)
    )
    .Series(series =>
    {
        series.Pie(
            model => model.Percentage,
            model => model.StatusName,
            null,
            null
        );
    })
    .Tooltip(tooltip => tooltip.
        Template("${ category } - ${ value }%").Visible(true)
    )
)
Nic
  • 12,220
  • 20
  • 77
  • 105
user2773195
  • 1
  • 1
  • 2

1 Answers1

0

You probably need to specify the model if you want to define your series like that. See this example

For example:

@(Html.Kendo().Chart<StatusPercentageViewModel>()
    .Name("StatusBreakdown")
    .Legend(legend => legend.Position(ChartLegendPosition.Bottom))
    .DataSource(ds => ds.Read(read => read.Action("GetStatus", "Status")))
    .Series(series =>
    {
        series.Pie(
            model => model.Percentage,
            model => model.StatusName
        );
    })
    .Tooltip(tooltip => tooltip.Template("${ category } - ${ value }%").Visible(true))
)

Another way (more similar to what you have now) to do it would be:

@model IEnumerable<StatusPercentageViewModel>
@(Html.Kendo().Chart()
    .Name("StatusBreakdown")
    .Legend(legend => legend.Position(ChartLegendPosition.Bottom))
    .Series(series => series.Pie(Model))
    .Tooltip(tooltip => tooltip.Template("${ category } - ${ value }%").Visible(true))
)
Nic
  • 12,220
  • 20
  • 77
  • 105
  • What about this problem??? http://stackoverflow.com/questions/28897992/showing-data-by-percentage-on-pie-charts-in-mvc – Jack Mar 06 '15 at 14:14