Interaction and Export
Export Snapshot Link
Canvas content is converted into a data URL and assigned to a download link so the drawing can be saved.
Program
toDataURL serializes the current canvas bitmap. A link with download can offer that image as a file.
export_snapshot_link.html
<canvas id="chart" width="320" height="180"></canvas><a id="save" download="chart.png">Save chart</a>
<script>
const chart = document.querySelector("#chart");
const save = document.querySelector("#save");
const ctx = chart.getContext("2d");
ctx.fillStyle = "#0f766e";
ctx.fillRect(24, 36, 180, 72);
const url = chart.toDataURL("image/png");
save.href = url;
</script>
toDataURL
toDataURL converts the canvas bitmap into an encoded image URL.
download
The download attribute suggests saving a link target as a file.