[Chartjs]-Chartjs cannot read property datasets of undefined

9👍

Turns out I was using the wrong npm package.

Be warned, somebody has been sitting for 2 years on the name chartjs with an outdated, stale github repo. The real package name is chart.js. Very annoying.

8👍

I did create a fiddle (I just copied your code into custom component) for you and there is no error in my case.

I think that there is error around here, as your chart is not being updated properly:

this.usageChart.data.datasets.forEach((dataset) => {
  dataset.data.shift();
  dataset.data.push(usages[dataset.label]);
});

Corrected version:

You were wrongly updating the data sets:

this.usageChart.data.datasets.forEach((dataset) => {
  dataset.data.shift();
  dataset.data = usages[dataset.label];
});

Please check the working fiddle and compare it with your project.

Leave a comment