简体   繁体   English

如何在 Cube.js 中使用 pivotConfig?

[英]How to use pivotConfig in Cube.js?

My resultSet looks like this:我的resultSet如下所示:

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:我想 pivot 它得到这个:

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?我可以使用tablePivot来执行此操作吗? If yes, how to set pivotConfig ?如果是,如何设置pivotConfig

The final goal is to render this formatted resultSet as a stacked barchart with Recharts .最终目标是将此格式化的结果集呈现为带有resultSet堆叠条形图


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:我相信您需要这样的pivotConfig

resultSet.tablePivot({
  x: [ 'Error.type' ],
  y: [ 'Error.criticity', 'measures' ]
})

The pivoted result will look like this, which is pretty much what you expect it to be, right?旋转后的结果将如下所示,这几乎是您所期望的,对吧?

[
  {Error.type: "A", ORANGE,Error.count: "10", GREEN,Error.count: "1"},
  {Error.type: "B", ORANGE,Error.count: "8", GREEN,Error.count: "6"},
  {Error.type: "C", ORANGE,Error.count: "5", GREEN,Error.count: "1"}
]

You can read more about pivotConfig in Cube.js documentation .您可以在 Cube.js文档中阅读有关pivotConfig的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM