如何解决Chartjs导出图像导出空的暗图像
我正在尝试使用chartjs导出图表的图像,但是除了黑屏外什么都没有显示。 我在做什么错了?
options: {
responsive: true,maintainAspectRatio: false,animation: {
onComplete: function(animation){
document.getElementById("download").addEventListener('click',function(){
var url_base64jp = document.getElementById("labChart").toDataURL("image/png");
var a = document.getElementById("document");
a.href = url_base64jp;
});
}
},
我的按钮
<a id='download' download='invoice-report.png' href=""
class="btn btn-primary pull-right bg-flat-color-1"
title="Invoice Report">
Save as Image</a>
解决方法
我添加了这段代码以使背景变白:
Chart.plugins.register({
afterRender: function(c) {
var ctx = c.chart.ctx;
ctx.save();
ctx.globalCompositeOperation = 'destination-over';
ctx.fillStyle = 'white';
ctx.fillRect(0,c.chart.width,c.chart.height);
ctx.restore();
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。