jquery - How to get data on x-axis and number of times occured on y-axis using crossfilter JS? -


i using crossfilter data on x-axis , number of times occured on y-axis.

     var data = [{      owner: "alyssa",     id: "a"     }, {         owner: "alyssa",        id: "a"     }, {        owner: "alyssa",        id: "a"   }, {       owner: "alyssa",       id: "a"   }, {       owner: "alyssa",       id: "b"      }, {     owner: "bob",     id: "a"  }, {     owner: "bob",     id: "d" }, { owner: "joe", id: "a" }, {    owner: "joe",     id: "a" }, {     owner: "joe",     id: "d" }, {     owner: "joe",     id: "d"  }]; var dropdown_cross1 = crossfilter(data);  var x_owner_filter=dropdown_cross1.dimension(function (d){          (var key in d)         {              if(d[key] == "d")             {                 //console.log("selected_text="+selected_text);                 //console.log('key=' + key + ' value=' + d[key]);                  console.log(d[key]);                  return d[key];             }            }      });     //x_owner_filter.filter("d");      var y_owner_filter = x_owner_filter.group().reducecount();       var size=y_owner_filter.size();     console.log("size="+size);      var size_ownertitle = y_owner_filter.top(size);     console.log(size_ownertitle); 

output

[object { key="d",  value=11}] 

output must be [object { key="d", value=3}]

i new crossfillter, not know the problem?

here jsfiddle see output in browser's console.

see updated jsfiddle

if you're expecting count ds, id dimension, simply:

var x_id_dim = dropdown_cross1.dimension(function (d){     return d.id; }); 

now, y values come group associated dimension:

var y_id_group = x_id_dim.group().reducecount(); 

you might want owner dimension, create separately.

i suspect confusion here might crossfilter definition of "dimension" - mean "some key want bin , filter on" not dimension in x , y. typically y chart-dimension come group aggregation.


Comments