How to update d3.js bar chart with new data

后端 未结 2 1927
有刺的猬
有刺的猬 2020-12-06 05:54

I’ve started with the “Let’s make a bar chart I” example here: http://bost.ocks.org/mike/bar/

And I’m having a hard time figuring out how to make the very simple bar

2条回答
  •  鱼传尺愫
    2020-12-06 06:41

    I have create a fiddle for you here. It is a simple take on what you had with a few changes, particularly separating the enter, update and exit selections. This should help you start understanding the update process in D3.

    // enter selection
    bars
        .enter().append("div");
    
    // update selection
    bars
        .style("width", function (d) {return scale(d) + "%";})
        .text(function (d) {return d;});
    
    // exit selection
    bars
        .exit().remove();
    

提交回复
热议问题