show percent value in the middle #10077
Replies: 4 comments 6 replies
-
No, not by default, you will need to use/write a custom plugin to achieve this. You can see my stack answer here for an indication of it: https://stackoverflow.com/questions/67486126/how-to-add-text-inside-the-doughnut-chart-using-chart-js-version-3-2-1 const plugin = {
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();
}
} |
Beta Was this translation helpful? Give feedback.
-
yes the way is not bad, but I need each percent value in the middle, if I click on a data element. can we realize this ? |
Beta Was this translation helpful? Give feedback.
-
@Ghost108 maybe a plugin is not really needed. I have done a prototype leveraging Clicking on the dataset item, the percentage is shown in the middle. |
Beta Was this translation helpful? Give feedback.
-
Thats very gopd ! |
Beta Was this translation helpful? Give feedback.
-
Hi everyone !
I would like to create a doughnut chart like this example:
https://www.chartjs.org/docs/latest/samples/other-charts/doughnut.html
Is there a way to show the percent value of a selected data in the middle ?
Beta Was this translation helpful? Give feedback.
All reactions