javascript - Chartjs 导出 ImageExports 空暗图像
问题描述
我正在尝试使用 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, 0, c.chart.width, c.chart.height);
ctx.restore();
}
});
推荐阅读
- python - 重塑 np 数组的块
- python - 手动构造日期时间对象时出现意外的时区偏移
- php - 来自 html 周输入的 PHP 日期字符串
- node.js - 您如何获取在 firebase .on 中更新的孩子?
- express - 如何在 MERN 堆栈中发送响应模式?
- devops - jFrog 构建 - 如何不删除生产工件
- c# - 我如何误用 NotThrowAsync
- python - 使用集合中的值命名递归创建的数据框
- javascript - keydown 上的滚动事件,如向下箭头和向上箭头
- node.js - 为什么当 node_modules 包含在卷中时找不到任何开发库?