Chart JS text centre in doughnut chart

  Kiến thức lập trình

I have a circle with text within my doughnut chart js, how can i centre the text, seems to be different position depending on screens.

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

ctx.beginPath();
var fontSize = (height / 114).toFixed(2);
ctx.font = fontSize + "em sans-serif";
ctx.arc(width/2,height/2,55,0,2*Math.PI);
ctx.fillStyle = '#006072';
ctx.fill();
ctx.lineWidth = 1;
ctx.fillStyle = 'white';
ctx.strokeStyle = '#CBE1EF';
ctx.stroke();
ctx.fillText(text, textX, textY);
ctx.save();

     

    var text ="$" +  Math.round( round_number / Math.pow(10,zeroCount) ) + "M +",
      textX = Math.round((width - ctx.measureText(text).width) / 2),
      textY = height / 1.9;

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

LEAVE A COMMENT