【问题标题】:Kendo Pie Chart MVC Data Binding剑道饼图 MVC 数据绑定
【发布时间】:2014-12-10 16:46:31
【问题描述】:

我在 MVC 中遇到 Telerik 的 Kendo UI 饼图问题。我在他们的网站上找不到任何像样的代码示例。我发现的一个演示只显示了一半的代码,所以我试着猜测如何让它工作。我遇到了一个错误,无论我如何尝试消除该错误,似乎都没有任何效果。您实际绑定数据的 series.Pie 部分存在问题。我复制了他们示例中的代码,并像他们一样使用了 lambda 表达式。 model => model.Percentage 和 model => model.StatusName 与我的视图模型一起使用。但它在第一个 lambda 时出错,并带有以下错误消息:

CS1660:无法将 lambda 表达式转换为类型“字符串”,因为它不是委托类型

以下是相关代码:

视图模型/视图:

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)
    )
)

【问题讨论】:

    标签: kendo-ui kendo-asp.net-mvc kendo-dataviz kendo-chart


    【解决方案1】:

    如果您想这样定义您的系列,您可能需要指定型号。见this 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))
    )
    

    另一种方式(更类似于您现在的方式)是:

    @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))
    )
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多