score:0

var data = {
  labels: [
    "red",
    "blue",
    "yellow"
  ],
  datasets: [{
    data: [300, 50, 100],
    backgroundcolor: [
      "#ff6384",
      "#36a2eb",
      "#ffce56"
    ],
    hoverbackgroundcolor: [
      "#ff6384",
      "#36a2eb",
      "#ffce56"
    ]
  }]
};

var promiseddeliverychart = new chart(document.getelementbyid('mychart'), {
  type: 'doughnut',
  data: data,
  options: {
    responsive: true,
    plugins: {
      legend: {
        display: false
      }
    }
  },
  plugins: [{
    id: 'text',
    beforedraw: function(chart, a, b) {
      var width = chart.width,
        height = chart.height,
        ctx = chart.ctx;

      ctx.restore();
      var fontsize = (height / 240).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();
    }
  }]
});
<body>
  <canvas id="mychart"></canvas>
  <script src="https://cdn.jsdelivr.net/npm/chart.js@3.2.0/dist/chart.min.js"></script>
</body>

score:3

you will have to use a custom plugin for that

var data = {
  labels: [
    "red",
    "blue",
    "yellow"
  ],
  datasets: [{
    data: [300, 50, 100],
    backgroundcolor: [
      "#ff6384",
      "#36a2eb",
      "#ffce56"
    ],
    hoverbackgroundcolor: [
      "#ff6384",
      "#36a2eb",
      "#ffce56"
    ]
  }]
};

var promiseddeliverychart = new chart(document.getelementbyid('mychart'), {
  type: 'doughnut',
  data: data,
  options: {
    responsive: true,
    plugins: {
      legend: {
        display: false
      }
    }
  },
  plugins: [{
    id: 'text',
    beforedraw: function(chart, a, b) {
      var width = chart.width,
        height = chart.height,
        ctx = 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();
    }
  }]
});
<body>
  <canvas id="mychart"></canvas>
  <script src="https://cdn.jsdelivr.net/npm/chart.js@3.2.0/dist/chart.min.js"></script>
</body>


Related Query

More Query from same tag