请参阅此处的工作小提琴:
” nofollow noreferrer“数据数组,用户为组提供了多个键。我想将 d3.groups
通过这些密钥进行分组。
在我的小提琴示例中,我知道我可以“手动”链接两个键以获取我想要的东西:
var gps = d3.groups(objs, d => d.Eye, d => d.Sex)
但是我硬编码 d.yee
/ d.sex
。 。
var gb_keys = ['Eye','Sex']
var gps = d3.groups(obj,d=>gb_key.map(x=>d.x)//Doesn't work but just a random idea/thought
com/porate/43973917/by-by-by-with-multiple-fields-using-d3-js> group by the comp by lother comply d3.js ,但问题很旧,我想知道是否d3 a - 基于基于的解决方案现在存在。 ?
See working fiddle here: https://jsfiddle.net/0qgtbk9r/9/
Say I have an array of objects for data, and the user has supplied multiple keys to group by. I want to utilize d3.groups
to group by those keys.
For my fiddle example, I know I can chain the two keys "manually" to get what I want:
var gps = d3.groups(objs, d => d.Eye, d => d.Sex)
But I'm hard coding d.Eye
/ d.Sex
...
So my question is how to get to same result if I supply an array of the keys to do the grouping by... something like this:
var gb_keys = ['Eye','Sex']
var gps = d3.groups(obj,d=>gb_key.map(x=>d.x)//Doesn't work but just a random idea/thought
This is similar/almost duplicate to Group by with multiple fields using d3.js but the questions are pretty old and I'm wondering if a d3-based solution exists out there now. ?
发布评论
评论(1)
d3.flatgroup
和 d3.flatrollup ,在V7中介绍了该问题,该问题涉及以下问题。 其他问题您提到的嵌套结构。
对于用户定义的密钥数组,您可以在
d3.flatgroup
(和d3.groups
等)中使用此方法:工作示例:
要解决一系列对象而不是数组数组的要求,您可以做到这一点:
工作示例:
d3.flatGroup
and d3.flatRollup were introduced in v7 which address the issue of the nested structure tackled in the other question you referenced.For a user-defined array of keys, you can use this approach in
d3.flatGroup
(andd3.groups
etc):Working example:
To address a requirement of an array of objects rather than an array of arrays you can do this:
Working example: