Skip to content

Instantly share code, notes, and snippets.

@gabrielqmatos88
Last active October 12, 2021 13:17
Show Gist options
  • Save gabrielqmatos88/b17f77ba2b1d7fe89926b5ab5df9f517 to your computer and use it in GitHub Desktop.
Save gabrielqmatos88/b17f77ba2b1d7fe89926b5ab5df9f517 to your computer and use it in GitHub Desktop.
Consolidando soma dos dados para exibir no gráfico
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