I am trying to get a stacked bar chart to transition in the same way as this bar chart - http://www.animatedcreations.net/d3/animatedBarChart_Slide.html
I have been following Mike Bostock's "A bar chart, part 2" example, and things are OK up to transitioning the stacked bars in and out.
My broken example is here - http://www.animatedcreations.net/d3/stackedBarChart7.html
I am reasonably sure the problem is with how I set up the data, as shown below. I am even wondering if the data needs to be transformed to be in columns rather than layers?
Insight much appreciated :) Thanks.
From redraw():
// stack the new data
var stacked = d3.layout.stack()(["act1", "act2","act3","other"].map(function(activity){
return stats.map(function(d) {
return {x:(d.hour), y: +d[activity]};
});
}));
// update x axis
x.domain(stacked[0].map(function(d) { return d.x; }));
var valgroup = graph.selectAll("g.valgroup").data(stacked);
// want the data in d. var rect contains the data AND functions.
// I am guessing this is where it all breaks??
var rect = valgroup.selectAll("rect")
.data((function(d) { return d; }), (function(d) { return d.x; }));
// new data set. slide by hour on x axis.