DataCount graph, filtered by size

I have a list of attendees for various events as a data source

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

      

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

I tried to create a dimension

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

      

but can't use it in dataCount

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

      

How to do it?

+3


source to share


1 answer


It looks to me like you are trying to use the data count widget to count group boxes, not rows.

The data counting widget is only for counting records, not keys or groups or anything else. But you could trick the objects, since the widget only calls .size()

for dimension and just .value()

in a group.

But what to put there? The meaning is actually simple, since this is the number of groups with a non-zero value:

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

      

But what size? Well, according to the cross filter documentation, group.size actually returns what we want, "the number of distinct values ​​in a group, regardless of any filters, cardinality."



So strange it seems

widget.dimension(eventGroup)

      

must work. Of course, I haven't tested this, so please comment if it doesn't work!

(Sigh, whatever I would do for a real data model in dc.js. It's rather confusing that the "dimension" of this widget is actually a crossfilter object. Another place where there is some strange economics of methods like group dimensions which is just a function.)

+1


source







All Articles