[Chartjs]-Display text in center of doughnut

2👍

If you could share some of your code that would help quite a bit, but not having used Chart.js I did some searching and found this:

https://jsfiddle.net/cmyker/ooxdL2vj/

Chart.pluginService.register({
  beforeDraw: function(chart) {
    var width = chart.chart.width,
        height = chart.chart.height,
        ctx = chart.chart.ctx;

    ctx.restore();
    var fontSize = (height / 114).toFixed(2);
    ctx.font = fontSize + "em sans-serif";
    ctx.textBaseline = "middle";

    var text = "75%",
        textX = Math.round((width - ctx.measureText(text).width) / 2),
        textY = height / 2;

    ctx.fillText(text, textX, textY);
    ctx.save();
  }
});

Hope this helps!

Leave a comment