Converting Chart.js canvas chart to image using .toDataUrl() results in blank image

前端 未结 7 2021
失恋的感觉
失恋的感觉 2020-11-30 23:57

I am using Chart.js. I am trying to convert the chart to an image by getting a base 64 string. The tutorial (http://www.chartjs.org/docs/) devotes an entire 1 line on the to

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 00:02

    First convert your Chart.js canvas to base64 string.

    var url_base64 = document.getElementById('myChart').toDataURL('image/png');

    Set it as a href attribute for anchor tag.

    link.href = url_base64;

    Save as Image

提交回复
热议问题