Accepted answer

I think if you log staffCounter.all() you'll find that it is counting managers, MITs, and Instores in 3 separate bins. This is because your dimension is sorting by Rank, then your group is binning again by Rank, so you end up with one bin per rank.

Normally you will want to pass a groupAll object, with one bin, to the numberDisplay. However, it is permissive and will also accept ordinary groups with multiple bins (source). It will sort the bins and take the last.

Why? I'm not sure. I think in almost every case you will want to reduce to one bin, but someone clearly had a use case where they wanted to display the largest value out of many bins.

I was surprised to find that the behavior is not documented, so I've updated the numberDisplay documentation.

With a groupAll your code will look something like:

var staffCounter = ndx.groupAll().reduce(add_item, remove_item, initialise);
    .valueAccessor(function(d) {
        return d.manager_count; // no .value here

Note that no crossfilter dimension is used here.

Related Query

More Query from same tag