React-chartjs-2 圆环图导出到 png [英] React-chartjs-2 Doughnut chart export to png

查看:80
本文介绍了React-chartjs-2 圆环图导出到 png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 react-chartjs-2 库创建了一个甜甜圈和条形图.现在我想将此图表导出为 png,即图表在用户单击时下载为 png.我尝试了很多方法,但都没有成功.其中之一是使用 html2canvas 库并获取屏幕截图,但这会降低图表的质量.我想知道 react-chartjs-2 库中有没有直接导出图表的函数?

I have created a Doughnut and Bar chart using react-chartjs-2 library. Now I want to export this chart as png i.e the chart gets downloaded as png on user click. I have tried many ways but could not succeed. One of them was to use html2canvas library and get a screenshot but that is degrading the quality of chart. I am wondering is there any function in react-chartjs-2 library to directly export the chart?

编辑 - 如果有人能告诉我关于 javascript 中的任何其他库,我可以在其中制作 Bar 和 Donut 等图表,并且该库为我提供了直接导出图表的功能,那也会很有帮助.

Edit- If someone can tell me about any other library in javascript in which I can make the charts like Bar and Doughnut and that library gives me the function to directly export the chart, that would also be helpful.

推荐答案

我能够使用 react-chartjs-2 库本身的 .toBase64Image() 函数来做到这一点.

I was able to do it using .toBase64Image() function from react-chartjs-2 library itself.

这篇关于React-chartjs-2 圆环图导出到 png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆