score:1

Accepted answer

There are easier and better ways to create a selection with the total of each stacked bar. However, using your code and applying the minimum possible changes, just show the third object for each stacked bar:

.text(function(d, i) {
    if (i === 2) return formatText(d["x1_" + TEAM])
});

Or, if you want to do it without a magic number:

.text(function(d, i) {
    if (i === textOnBar4.data().length - 1) return formatText(d["x1_" + TEAM])
});

Here is your updated plunker: https://plnkr.co/edit/iovKsrx0Eg4pTUWTDUaA?p=preview


Related Query