Creating Stacked Charts In Dc Js With Panel Dataset
I'm having trouble creating a stacked barchart, I cannot figure out how to properly apply the dimensions to a panel dataset My data looks like this: Date name value 12/1/15 n
Solution 1:
Here's how to produce the group, from the FAQ:
var group = dimension.group().reduce(
function(p, v) { // add
p[v.type] = (p[v.type] || 0) + v.value;
return p;
},
function(p, v) { // remove
p[v.type] -= v.value;
return p;
},
function() { // initialreturn {};
});
(In your case, v.name
instead of v.type
.)
Basically you create a group which reduces to objects containing the values for each stack.
Then use the name and accessor parameters of .group()
and .stack()
. Unfortunately you have to spell it out, as the first has to be .group
and the rest .stack
.
As so:
chart.group(group, 'name1', function(d) { return d.name1; })
.stack(group, 'name2', function(d) { return d.name2; })
.stack(group, 'name3', function(d) { return d.name3; })
...
(Somewhere on SO or the web is a loop form of this, but I can't find it ATM.)
Post a Comment for "Creating Stacked Charts In Dc Js With Panel Dataset"