Chartjs-Line Chart is not setting backgroundColor when created dynamically Chart.js

0👍

Based on the current information it sounds like somehow the problem is specific to data coming from the function, although I don’t see anything obviously wrong with the function. So instead I would try focusing on the general debugging strategy of simplifying the problem — in this case simplifying the function to make it closer to the hardcoded data that is working as expected. I suggest something like this, which is about as simple as possible:

function createNewDataset(data, label) {
  return {

    // change to `label: label` once working:
    label: "Test",

    lineTension: 0.3,
    backgroundColor: "rgba(102,223,56,0.71)",
    borderColor: "rgb(114,223,52)",
    pointRadius: 3,
    pointBackgroundColor: "rgb(91,223,88)",
    pointBorderColor: "rgb(93,223,65)",
    pointHoverRadius: 3,
    pointHoverBackgroundColor: "rgb(89,223,47)",
    pointHoverBorderColor: "rgb(125,223,72)",
    pointHitRadius: 10,
    pointBorderWidth: 2,

    // change to `data: data` once working:
    data: [0, 10000, 5000, 15000, 100000, 20000, 15000, 25000, 20000, 30000, 25000, 40000]

  };
}

Leave a comment