Good morning everyone
So my project is to render some graphics in canvas and then, after everything is drawn, save it as an image and put on the website, in a html img
tag.
Is there any way I can detect whether my drawing is finished or not?
I’m throwing an event after drawing the chart. But by that time the image has not been rendered yet and canvas returns an empty image with canvas.getDataURL()
. Is there any way except using timeouts or delays?
the code that doesn’t work
this.add(this._beaconPieChart);
const event = new Event("pieChartIsReady");
window.dispatchEvent(event);
the code that works
this.add(this._beaconPieChart);
const event = new Event("pieChartIsReady");
setTimeout(() => {
window.dispatchEvent(event);
}, 16);