Chartjs-Having trouble fetching data from database for chart in ASP .NET Core

1👍

If the backend is like below, the data you get is just a simple decimal.

var plan = _azdb.WorkTs.Where(w => w.org == "ООО \"МТК\"")
                       .Where(w => w.dtMonth.Value.Year == 2021)
                       .Select(w => w.hrPlan)
                       .Sum();

data in datasets should be an array. You need change like below:

datasets: [{
    label: 'Plan hours',
    data: [data],    //change here...
    backgroundColor: 'rgb(161, 221, 239)',
    borderColor: 'rgb(161, 221, 239)',
},
{
    label: 'Sub hours',
    data: [data2],     //change here...
    backgroundColor: 'rgb(254, 171, 133)',
    borderColor: 'rgb(254, 171, 133)',
},
{
    label: 'Fact hours',
    data: [data3],    //change here...
    backgroundColor: 'rgb(127, 137, 138)',
    borderColor: 'rgb(127, 137, 138)',
}]

Leave a comment