I read a lot of documentation about adding label on a D3 bar chart but i can\'t figure it out. I am stuck with what to add after the \"svg.selectAll(\"text\")\".
Th
This should work !
var yTextPadding = 20;
svg.selectAll(".bartext")
.data(data)
.enter()
.append("text")
.attr("class", "bartext")
.attr("text-anchor", "middle")
.attr("fill", "white")
.attr("x", function(d,i) {
return x(i)+x.rangeBand()/2;
})
.attr("y", function(d,i) {
return height-y(d)+yTextPadding;
})
.text(function(d){
return d;
});
Notice how I use a class (.bartext) to identify the chart labels.