简体   繁体   English

将 Canvas 图表导出为 png 和 pdf

[英]Export Canvas Charts to png and pdf

I am working on a data visualization project and I have used the Chart.js library for drawing and now I need to export the charts in pdf and png format, what is the best way for me to do it correctly?我正在做一个数据可视化项目,我使用了 Chart.js 库进行绘图,现在我需要以 pdf 和 png 格式导出图表,我正确执行此操作的最佳方法是什么? Thanks for helping my friends...感谢帮助我的朋友...

If you want to create a feature to allow a user to download the created charts into a image, you can use the 'toDataURL()' function, and specify the canvas of each chart.如果要创建功能以允许用户将创建的图表下载到图像中,可以使用“toDataURL()” function,并指定每个图表的 canvas。

To download a canvas as a pdf you can use the jsPDF library, using the above function to retrieve the canvas and then specifying the dimensions. To download a canvas as a pdf you can use the jsPDF library, using the above function to retrieve the canvas and then specifying the dimensions.

I may be wrong but I believe you need to create the charts and display on a web page before converting them to an image/pdf.我可能错了,但我相信您需要创建图表并在 web 页面上显示,然后再将它们转换为图像/pdf。 Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM