dc.js: 如何在对象元素列表上减少计数?
dc.js: how to reduceCount on an object element list?
我有一个像这样的对象:
[ { "Project": 1; "key":["a", "b", "c", "d"]},
{ "Project": 2; "key":["b", "c", "d"]},
{ "Project": 3; "key":["e", "c", "a"]},
{ "Project": 4; "key":["b", "a", "e", "f"]}
]
就我实现的来说,reduceCount只统计单个元素值的出现次数。我想把它改成什么
key value
a 3
b 3
c 3
d 2
e 2
f 1
我想按它在单个项目中出现的次数来计算,例如 "a" 在 3 个项目中出现。实际上我想在我的词云中使用这些数据。
我可以在交叉过滤器之外执行此操作,但不确定如何通过交叉过滤器维度实现此操作。
非常感谢您的帮助。
Ethan Jewett 提到的解决方案
Is there a way to tell crossfilter to treat elements of array as separate records instead of treating whole array as single key?
如果你想在当前版本的Crossfilter中做到这一点,你需要使用groupAll。这个问题的答案提供了一个例子:Is there a way to tell crossfilter to treat elements of array as separate records instead of treating whole array as single key?
或者,您可以使用 Reductionio 库,它提供了一种非常容易地为复杂组生成 reduce 函数的方法,并且在这种情况下以与 dc.js 兼容的方式包装 groupAll。文档的相关部分在这里:https://github.com/crossfilter/reductio#aggregations-groupall-aggregations-reductio-b-groupall-b-i-groupingfunction-i-
如果您特别喜欢冒险,可以尝试使用位于 https://github.com/crossfilter/crossfilter. We have recently added a new parameter to the dimension
call that will cause it to treat your data exactly as you describe. Documentation is here: https://github.com/crossfilter/crossfilter/wiki/API-Reference#dimension
的 Crossfilter fork 的 master 分支
我有一个像这样的对象:
[ { "Project": 1; "key":["a", "b", "c", "d"]},
{ "Project": 2; "key":["b", "c", "d"]},
{ "Project": 3; "key":["e", "c", "a"]},
{ "Project": 4; "key":["b", "a", "e", "f"]}
]
就我实现的来说,reduceCount只统计单个元素值的出现次数。我想把它改成什么
key value
a 3
b 3
c 3
d 2
e 2
f 1
我想按它在单个项目中出现的次数来计算,例如 "a" 在 3 个项目中出现。实际上我想在我的词云中使用这些数据。
我可以在交叉过滤器之外执行此操作,但不确定如何通过交叉过滤器维度实现此操作。
非常感谢您的帮助。
Ethan Jewett 提到的解决方案
Is there a way to tell crossfilter to treat elements of array as separate records instead of treating whole array as single key?
如果你想在当前版本的Crossfilter中做到这一点,你需要使用groupAll。这个问题的答案提供了一个例子:Is there a way to tell crossfilter to treat elements of array as separate records instead of treating whole array as single key?
或者,您可以使用 Reductionio 库,它提供了一种非常容易地为复杂组生成 reduce 函数的方法,并且在这种情况下以与 dc.js 兼容的方式包装 groupAll。文档的相关部分在这里:https://github.com/crossfilter/reductio#aggregations-groupall-aggregations-reductio-b-groupall-b-i-groupingfunction-i-
如果您特别喜欢冒险,可以尝试使用位于 https://github.com/crossfilter/crossfilter. We have recently added a new parameter to the dimension
call that will cause it to treat your data exactly as you describe. Documentation is here: https://github.com/crossfilter/crossfilter/wiki/API-Reference#dimension