score:0

Accepted answer

you can try something like this fiddle, but i did not format and position the labels as of now, you can do it as you wish.

"oncomplete": function() {
        var chartinstance = this.chart,
          ctx = chartinstance.ctx;
          ctx.font = chart.helpers.fontstring(chart.defaults.global.defaultfontsize, chart.defaults.global.defaultfontstyle, chart.defaults.global.defaultfontfamily);
          ctx.textalign = 'center';
          ctx.textbaseline = 'bottom';
           var sums = [0, 0, 0];
          this.data.datasets.foreach(function(dataset, i) {
            var meta = chartinstance.controller.getdatasetmeta(i);
            meta.data.foreach(function(bar, index) {
              var data = dataset.data[index];
              ctx.filltext(data, bar._model.x, bar._model.y);
              sums[index] += data;
            });
            });
          sums.foreach(function(v, i) {
            ctx.filltext(v, 150*(i+1)+(i*50), 40);
          });
        }

score:0

the formatter is called for each datalabel, meaning for every bar. that's the reason why you get the same value on top of every bar.

possible solutions would be either to plot an "invisible" bar for the combined value or check inside the formatter function if it is called for the centered bar. then you could use mulitline labels to create a label which has the value for the current bar and the combined value as well.

edit:

after thinking about it the easiest way would be to use mixed charts. you can just calculate your combined values for each group and add a chart for these values. for example you add a line chart with showlines: false.

new chart('mymixedcharts', {
    type: 'bar',
    data: {
        labels: ['foo', 'bar'],
        datasets: [
          {
            label: "value 1",
            data: [12, 5]
          },
          {
            label: "value 2",
            data: [7, 8]
          },
          {
            label: "group value",
            data: [19, 13],
            type: "line",
            showlines: false
          }
        ]
    }
});

or as jsfiddle


Related Query

More Query from same tag