Last active
October 12, 2021 13:17
-
-
Save gabrielqmatos88/b17f77ba2b1d7fe89926b5ab5df9f517 to your computer and use it in GitHub Desktop.
Consolidando soma dos dados para exibir no gráfico
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [ | |
{ | |
x: 'Ala-04', | |
y: 1 | |
}, | |
{ | |
x: 'Ala-04', | |
y: 1 | |
}, | |
{ | |
x: 'Recursos Humano', | |
y: 3 | |
}, | |
{ | |
x: 'Recursos Humano', | |
y: 2 | |
}, | |
{ | |
x: 'Lavanderia', | |
y: 1 | |
}, | |
{ | |
x: 'Recursos Humano', | |
y: 1 | |
}, | |
{ | |
x: 'Ala-03', | |
y: 1 | |
} | |
]; | |
const tmpObj = data.reduce((rs, item) => { | |
rs[item.x] = (rs[item.x] || 0 ) + item.y; | |
return rs; | |
}, {}); | |
const result = Object.keys(tmpObj).map(key => ({x: key, y: tmpObj[key]})); | |
console.log('result', result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment