Duplicate How to Display Values in a Stacked Multi-bar chart - nvd3 Charts
There is a fix that you can implement at https://gist.github.com/topicus/217444acb4204f364e46
EDIT: copied the code if the github link is removed:
d3.selectAll('.nv-multibar .nv-group').each(function(group){
var g = d3.select(this);
g.selectAll('text').remove();
g.selectAll('.nv-bar').each(function(bar){
var b = d3.select(this);
var barWidth = b.attr('width');
var barHeight = b.attr('height');
g.append('text')
.attr('transform', b.attr('transform'))
.text(function(){
return parseFloat(bar.y).toFixed(2);
})
.attr('y', function(){
var height = this.getBBox().height;
return parseFloat(b.attr('y')) - 10;
})
.attr('x', function(){
var width = this.getBBox().width;
return parseFloat(b.attr('x')) + (parseFloat(barWidth) / 2) - (width / 2);
})
.attr('class', 'bar-values');
});
});
source
share