D3 - Update bar chart data onclick

前端 未结 2 1969
南旧
南旧 2021-01-22 13:22

I am trying to update my web page content when the user clicks on a button using D3. Unfortunately I can see that onclick new data is being displayed, but the old data is not fo

2条回答
  •  不要未来只要你来
    2021-01-22 13:47

    You need to select the elements that actually exist and do that only once:

    var sel = svg.selectAll("rect")
                 .data(data);
    
    sel.exit().remove();
    sel.enter().append("rect")
    // etc
    

提交回复
热议问题