Skip to content Skip to sidebar Skip to footer

Dc.js: Stacked Area Chart Using Reducecount Method

I'm fairly new to the dc.js/crossfilter/d3 trifecta, and have a question about grouping variables for building a stacked area chart. I've been following tutorials like this one tha

Solution 1:

There are a number of ways to do this. To get it working the way you tried, you'll want your reduce function to (always) return a value, so

var group_A = dateDim.group().reduceCount(function(d) {
    if (d.group == "A") return1; 
    elsereturn0; 
});

Another thing people commonly do is reduce all the values into one composite group:

var group = dateDim.group().reduce(function(p, d) {
    p[d.group] = (p[d.group] || 0) + 1;
    return p;  
  },
  function(p, d) {
    --p[d.group];
    return p;
  },
  function() { return {}; }
);

Then you'd use accessors for your stack calls:

.stack(group, function(d) { return d["A"] || 0; })

Post a Comment for "Dc.js: Stacked Area Chart Using Reducecount Method"