1๐
โ
If you want to draw something in the canvas, you can not hook the afterDatasetUpdate
because this is invoked when the dataset are updated, not drawn.
You should use afterDatasetDraw
hook.
const updateGaugeChartText = {
id: 'currentChartValue',
afterDatasetDraw(chart, args, pluginOptions) {
const { ctx } = chart;
const meta = args.meta;
const xCoor = meta.data[0].x;
const yCoor = meta.data[0].y;
ctx.save();
ctx.textAlign = 'center';
ctx.font = '32px sans-serif';
ctx.fillText(chart.data.datasets[0].data[0], xCoor, yCoor);
ctx.restore();
},
};
Source:stackexchange.com