Kendo Pie Chart won't render (remote data)

626 Views Asked by At

This is just one example of the many iterations I tried. Essentially, I want to show a pie chart with job types by cost amount. I am able to connect to the database fine, I was able to successfully make a Kendo grid. Any and all help is appreciated!

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

There are 1 best solutions below

2
On BEST ANSWER

Flip your values around for the pie chart series data:

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

The method signature is this:

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 only accepts numeric values for the expressionValue parameter.