Updating D3 streamgraph with new data

﹥>﹥吖頭↗ 提交于 2019-12-06 08:48:10

Success!!

Finally got it. Instead of targeting layers, I should have been targeting the paths themselves!

So, call your new data,

    // Get the data again
    d3.csv("PopulationStats/UK.csv", function(error, data) {
        data.forEach(function(d) {
            d.date = format.parse(d.date);
            d.amount = +d.amount;
        });

Nest it

var layers = stack(nest.entries(data));

And update your paths.

   d3.selectAll("path")
   .data(layers)
  .transition()
   .duration(750)
   .style("fill", function(d, i) { return colours(i); })
   .attr("d", function(d) { return area(d.values); });

So simple, but took me 2 days to figure out!

Just a heads-up for anyone else who finds this -- the same technique also works to update the data in the Stacked Area Chart example (http://bl.ocks.org/mbostock/3885211). Was banging my head against the computer for a solid 4 hours until I stumbled across this. Thanks Daft!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!