按维度过滤的dataCount图 [英] dataCount graph filtered by a dimension

查看:95
本文介绍了按维度过滤的dataCount图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有各种事件的参与者列表作为数据源

I have a list of participants to various events as the data source

eventid,participant_name
42,xavier
42,gordon
11,john

...
默认情况下,dataCount会说他们是3位参与者,我需要显示事件数(所以2)

... by default, dataCount will say they are 3 participants, I need to display the number of events (so 2)

我尝试创建维度

var event = ndx.dimension(function(d) {
  return d.eventid;
})

但无法在dataCount中使用它

but can't manage to use it in dataCount

dc.dataCount(".dc-data-count")
  //.dimension(ndx) //working, but counts participants
  .dimension(event) // not working

我该怎么做?

推荐答案

在我看来,您正在尝试使用数据计数小部件来对组箱而不是行进行计数。

It sounds to me like you are trying to use the data count widget to count group bins rather than rows.

数据计数小部件仅用于计数记录,而不用于键或组或其他任何计数。但是您可以伪造对象,因为小部件仅在维度上调用 .size(),而在 .value()

The data count widget is only designed to count records, not keys or groups or anything else. But you could fake out the objects, since the widget is calling just .size() on the dimension, and just .value() on the group.

但是放在那儿呢?该值实际上很容易,因为它是具有非零值的组的计数:

But what to put there? The value is actually sort of easy, since it's the count of groups with non-zero value:

var eventGroup = event.group();
widget.group({value: function() {
    return eventGroup.all().filter(function(kv) { return kv.value>0; }).length;
})

但是大小是多少?好吧,根据交叉过滤器文档, group.size 实际上返回了我们想要,组中不同值的数量,独立于任何过滤器;基数。

But what is the size? Well, according to the crossfilter documentation, group.size actually returns what we want, "the number of distinct values in the group, independent of any filters; the cardinality."

所以奇怪的是,看起来

widget.dimension(eventGroup)

应该工作。当然,我还没有测试过任何一个,因此,如果这不起作用,请发表评论!

should work. Of course, I haven't tested any of this, so please comment if this doesn't work!

(S,我不会为真实数据做些什么dc.js中的模型。这个小部件的维度实际上是交叉过滤器对象,这令人感到困惑。在另一个地方,存在一种怪异的方法经济性,例如维的组,它只是一个函数。)

(Sigh, what I wouldn't do for a real data model in dc.js. It is rather confusing that the "dimension" for this widget is actually the crossfilter object. Another place where there is kind of a weird economy of methods, like the dimension's group, which is just a function.)

这篇关于按维度过滤的dataCount图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆