2👍
You shouldn’t use the chart dom element size but the chart area.
[{
id: 'text',
afterDatasetsDraw: function(chart) {
const {ctx, chartArea} = chart;
const {left, top, width, height} = chartArea;
ctx.save();
var fontSize = (height / 50).toFixed(2); // In my opinion this should be reevaluated
ctx.font = fontSize + "em sans-serif";
ctx.textBaseline = "middle";
ctx.fillStyle ="rgb(200,200,200)";
var text = "'.$numVal.'",
textX = Math.round((width - ctx.measureText(text).width) / 2),
textY = height / 2;
ctx.fillText(text, left + textX, top + textY);
ctx.restore();
}
}]
- Chartjs-Adding prefix or suffix like $ to data labels in plugins in react-chartjs-2
- Chartjs-DevExtreme Exporter prints blank page
Source:stackexchange.com