如何通过Model绑定Kendo堆叠条形图

时间:2015-07-22 05:03:28

标签: asp.net asp.net-mvc-4 kendo-ui kendo-asp.net-mvc

我正在尝试通过MVC模型绑定堆叠的kendo条形图,但是收到错误"无法将lambda表达式转换为' double'因为它不是代表类型"。

@(Html.Kendo().Chart(Model)
    .Name("chart3")
    .Title(title => title
        .Text("Comments per day")
        .Align(ChartTextAlignment.Left)
    )
    .Legend(legend => legend
        .Visible(false)
    )
    .Series(series =>
    {
        series.Column(new  double[]{model => model.PerIdlingHours}
        )
        .Labels(labels => labels.Background("transparent").Visible(true));
    })
    .CategoryAxis(axis => axis
        .Categories(model => model.DataDate)
        .MajorGridLines(lines => lines.Visible(false))
        .Line(line => line.Visible(false))
    )
    .ValueAxis(axis => axis.Numeric()
        .Max(28)
        .MajorGridLines(lines => lines.Visible(false))
        .Visible(false)
    )
) 

1 个答案:

答案 0 :(得分:1)

这是我们创建剑道条形图的方法

@model IEnumerable< Hitec.Blackbox.Models.AllMachinesUtilization>
<div class="chart-wrapper">
@(Html.Kendo().Chart(Model)
    .Name("DailyChart")
        .HtmlAttributes(new { style = "width:auto;height:200px" })
    .Title(title => title
        .Text("Daily Utilization Chart")
        .Align(ChartTextAlignment.Left)
    )
    .Legend(legend => legend
        .Visible(true)
        .Position(ChartLegendPosition.Bottom)  
    )
    .SeriesDefaults(seriesDefaults =>
        seriesDefaults.Column().Stack(ChartStackType.Stack100))
    .Series(series =>
    {
        series.Column(model => model.IdlingHours).Color("#b8b8b8");
        series.Column(model => model.StopHours).Color("#bb6e36");
        series.Column(model => model.EngineWorkingHours).Color("#f3ac32"); 
  })
            .CategoryAxis(axis => axis
                .Categories(model => model.DataDate)
                .MajorGridLines(lines => lines.Visible(false))
                .Line(line => line.Visible(false))
            )
                    .ValueAxis(axis => axis.Numeric()
                       // .Max(100)
                       .Visible(false)
                            .Line(line => line.Visible(false))
                        .MajorGridLines(lines => lines.Visible(true))
                        .Visible(false)
                    )
       .Tooltip(tooltip => tooltip
            .Visible(true)
            .Template("#= series.name #:<br/> #= value #")
                ))
            </div>