score:2

you can get the center position of each horizontal bar (inside meta.data loop) as follows :

var barwidth = bar._model.x - bar._model.base;
var centerx = bar._model.base + barwidth / 2;

and after getting the position, draw the count text accordingly...

chart.helpers.each(this.data.datasets.foreach(function(dataset, i) {
   var meta = chartinstance.controller.getdatasetmeta(i);
   chart.helpers.each(meta.data.foreach(function(bar, index) {
      var data = dataset.data[index];
      var barwidth = bar._model.x - bar._model.base;
      var centerx = bar._model.base + barwidth / 2;
      if (i == 0) {
         ctx.filltext(data, centerx, bar._model.y + 4);
      } else {
         ctx.filltext(data, centerx, bar._model.y + 4);
      }
   }), this);
}), this);

see - live demo


Related Query

More Query from same tag