I am trying to calculate the sum/total value of each stacked bar in the chart and display it above each bar
https://jsfiddle.net/n0zjpyow/1/
Desired output:
(note:totals not accurate in image)
I am using the nest and rollup functions but the result from this is the total of each series and not each stacked bar.
var keys = d3.nest()
.key(function(d) { return (d.key) })
.rollup(function (v) {
return d3.keys(v[0]).filter(function(p, i){return i}) //filter out the heading
.reduce(function(s, p){ //sum each of the other members
//p is the category being summed
return (s[p] = d3.sum(d3.values(v[0][p][0])), s);
}, {});
})
.map(data);
Output
{1: {values: 190000000}
2A: {values: 152000000}
2B: {values: 190000000}
Non: {values: 128000000}}
I am getting confused with how to apply this to the data structure i have for the chart (which cannot be modified)
How can i calculate the total of the values in each bar ? Thanks for any assistance.

