score:0

from what i see in your function for rendering the chart you are passing the data for each dataset as a parameter. instead, modify your backend to fetch the data for all datasets to look like:

{
  "loans": [2],
  "payments": [3]
  ...
}

i've added a function in my js to set the data accordingly for my chart:

function getchartdata(data) {
let chartdata = {
    labels: ["# of records"], // on your case this is enough
    datasets: []
};
object.keys(data).foreach(function(label, index) {
    chartdata.datasets.push({
        label: label,
        data: object.values(data[label]),
        bordercolor: colors[index]
    });
});

return chartdata;
}

colors is just an array with hex color strings, as many as you like. i've created a function to generate a random color if the datasets become too many.

then when i create my chart i simply pass the result of that function to the data of the chart.

you'll have modify this depending on your backend. check this fiddle.


Related Query

More Query from same tag