Accepted answer

Have a look at your screenshot, the translate attribute contains function u(n)..... The variable y is a function not the value of the rect Y-coord. To get that you need"y"). But then the text is also not visible I used y(d.value) but that is equivalent.

You have to add the texts just like the rects.

This you need to add to the d3v5 code I posted in

The text does not animate yet, use the same animation code as for the rect Y-coord. Or create the text at the end of the rect animation.

      .data(function(d) { return d.values; })
        .attr("class", 'bar-text')
        .attr("fill", "#000")
        .attr("text-anchor", "middle")
        .text(function (d) { return d.value; })
        .attr("x", function (d, i) { return x1.bandwidth() * (i+0.5); })
        .attr("y", function (d, i) { return y(d.value) + 8; });

Related Query

More Query from same tag