剑道饼图不会渲染(远程数据)

时间:2017-09-12 19:55:58

标签: c# asp.net-mvc razor kendo-ui kendo-chart

这只是我尝试的多次迭代的一个例子。基本上,我想按成本金额显示工作类型的饼图。我能够很好地连接数据库,我能够成功制作一个Kendo网格。任何和所有的帮助表示赞赏!

Report.cshtml

@(Html.Kendo().Chart<JobWebApp.Models.JobViewModel>()
            .Name("piechart")
            .Title("Job Types to Cost")
            .DataSource(dataSource => dataSource
                .Read(read => read.Action("Jobs_Read", "Reports").Type(HttpVerbs.Get))
            )
            .Legend(legend => legend
                .Position(ChartLegendPosition.Top)
            )
            .Series(series =>
            {
                series.Pie(
                    x => x.JOB_TYPE,
                    x => x.JOB_COST
                );
            })
        )

ReportsController.cs

    [HttpGet]
    public ActionResult Jobs_Read([DataSourceRequest]DataSourceRequest request)
    {
        return Json(GetJobs().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

    [NonAction]
    private IQueryable<JobViewModel> GetJobs()
    {
        return from job in dbEntities.Jobs
               select new JobViewModel
               {
                   ID = job.ID,
                   DATE = job.DATE,
                   JOB_TYPE = job.JOB_TYPE,
                   JOB_COST = job.JOB_COST
               };
    }

1 个答案:

答案 0 :(得分:2)

翻转饼图系列数据的值:

        .Series(series =>
        {
            series.Pie(
                x => x.JOB_COST,
                x => x.JOB_TYPE                    
            );
        })

方法签名是:

ChartPieSeriesBuilder<TModel> Pie<TValue>(Expression<Func<TModel, TValue>> expressionValue, Expression<Func<TModel, string>> categoryExpression <Func<TModel, string>> expressionColor = null, Expression<Func<TModel, bool>> expressionExplode = null, Expression<Func<TModel, bool>> expressionVisibleInLegend = null);

IIRC,kendo只接受expressionValue参数的数值。