score:1

Accepted answer

I think you should reshape your data so that it fits better into the Crossfilter paradigm. The following should get you what you want:

var data = [{"_1000_1249":0,"_1250_1499":2},{"_1000_1249":1,"_1250_1499":2},{"_1000_1249":2,"_1250_1499":3}]

var updatedData = []
for(var i=0; i < data.length; i++) {
    for(key in data[i]) {
    updatedData.push({
        key: key,
      value: data[i][key]
    })
  }
}

var cf = crossfilter(updatedData)
var dimension = cf.dimension(function(d) { return d.key; })
var group = dimension.group().reduceSum(function(d) { return d.value; })

console.log(group.all())

If you want to experiment, this is in a JSFiddle here: https://jsfiddle.net/esjewett/1d853fwj/3/


Related Query

More Query from same tag