Chartjs-Chart.js, Javascript, unable to sum a data set. Javascript return NaN and I am not sure why

0๐Ÿ‘

โœ…

So thanks to @Pointy for highlighting I was trying to sum a string. and then for @Margon for showing me how to correctly format my line of code.

replaced: sum = datasets[0].data.reduce((a, b) => a + b, 0); with: sum = datasets[0].data.reduce((a, b) => Number(a) + Number(b) , 0);

and that has solved my issues. Thank you all for the help.

Leave a comment