score:1

Accepted answer

You are not adding class to the text

This will select all DOM with class text

var texts = svg.selectAll(".text").data(data);



texts
.enter()
.append("text")
.attr("class","label text") <-- add text class here
.attr("x", (function(d) { return x(d.Country) + x.rangeBand() / 2 ; }  ))
                .attr("y", function(d) { return y(d.Value) + 1; })
                .attr("dy", ".75em")
                .text(function(d) { return d.Value; }); 

Now to remove all text on update

bars.exit().remove();
texts.exit().remove(); <--- add this to remove exited text

Related Query

More Query from same tag