You can access afterRender
hook by using plugins
.
And here are all the plugin api available.
In html file:
<html>
<canvas id="myChart"></canvas>
<div id="imgWrap"></div>
</html>
In js file:
var chart = new Chart(ctx, {
...,
plugins: [{
afterRender: function () {
// Do anything you want
renderIntoImage()
},
}],
...,
});
const renderIntoImage = () => {
const canvas = document.getElementById('myChart')
const imgWrap = document.getElementById('imgWrap')
var img = new Image();
img.src = canvas.toDataURL()
imgWrap.appendChild(img)
canvas.style.display = 'none'
}