My resultSet
looks like this:
0: Object { "Error.type": "A", "Error.criticity": "ORANGE", "Error.count": 10 }
1: Object { "Error.type": "B", "Error.criticity": "ORANGE", "Error.count": 8 }
2: Object { "Error.type": "B", "Error.criticity": "GREEN", "Error.count": 6 }
3: Object { "Error.type": "C", "Error.criticity": "ORANGE", "Error.count": 5 }
4: Object { "Error.type": "C", "Error.criticity": "GREEN", "Error.count": 1 }
5: Object { "Error.type": "A", "Error.criticity": "GREEN", "Error.count": 1 }
I would like to pivot it to get this:
0: Object { "Error.type": "A", "ORANGE": 10, "GREEN": 1}
1: Object { "Error.type": "B", "ORANGE": 8, "GREEN": 6 }
2: Object { "Error.type": "C", "ORANGE": 5, "GREEN": 1}
Can I use tablePivot to do this? If yes, how to set pivotConfig?
The final goal is to render this formatted resultSet
as a stacked barchart with Recharts.
I have tried:
resultSet.tablePivot({
x: ['Error.type'],
y: ['Error.criticity', 'Error.count'],
})
which returns
0: Object { "Error.type": "A", "Error.criticity": "ORANGE", "Error.count": undefined }
1: Object { "Error.type": "B", "Error.criticity": "ORANGE", "Error.count": undefined }
2: Object { "Error.type": "C", "Error.criticity": "ORANGE", "Error.count": 5 }
and
resultSet.tablePivot({
x: ['Error.type'],
y: ['Error.criticity', 'measures'],
})
which returns
0: Object { "Error.type": "A", "Error.criticity": "GREEN", "Error.count": 1 }
1: Object { "Error.type": "B", "Error.criticity": "GREEN", "Error.count": 6 }
2: Object { "Error.type": "C", "Error.criticity": "GREEN", "Error.count": 1 }
In both cases I lose some information.
I believe that you need a
pivotConfig
like this:The pivoted result will look like this, which is pretty much what you expect it to be, right?
You can read more about
pivotConfig
in Cube.js documentation.