Chartjs-How to sum array value in chart.js inside loop function?

0👍

You can use reduce() method for this like:

var datiedu2 = {
   "labels": ['Lavori non terminati', 'Lavori in corso'],
   "datasets": [{
      label: 'Numero',
      data: arrayItem.reduce((a, b) => a + ((b['Value 1'] || 0) + (b['Value 2'] || 0)), 0),
      backgroundColor: 'rgb(255, 99, 132)',
      borderWidth: 1
   }]
};

Leave a comment