score:3

Accepted answer

Two things make this work.

First, you can't write the labels until the transition is over since the rects won't have their proper height until then.

Second, you can get the rect height by using previousSibling of the text you just added. Putting this together:

d3.select('#chartContainer')
    .append("svg")
    .attr('width', width)
    .attr('height', height)
    .datum(nested_data)
    .transition().duration(1000)
    .call(chart)
    .each("end", function() {
      d3.selectAll(".nv-bar")
        .append("text")
        .attr("x", chart.xAxis.rangeBand() / 4)
        .attr("y", function(d) {
          return d3.select(this.previousSibling).attr('height') / 2;
        })
        .text(function(d) {
          return d.Value
        })
    });

Example here.


Related Query

More Query from same tag