下面是生成图表本身后生成图表图像的代码。 我只想看到图像。这可能吗?
我为图表的div尝试了display: none;
,但图像似乎也没有。
$(function() {
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ["July","August","September","October","November","December","January","February","March","April"],
datasets: [
{
label: 'This year',
data: [340,0,450,3240,360,200,0,0,1445,350],
}
, {
label: 'Last year',
data: [330,340,100,160,560,3600,320,0,397.5,300],
}
]
},
options: {
maintainAspectRatio: false,
responsive: true,
animation: {
onComplete: function(animation){
document.querySelector('#myChart').setAttribute('href', this.toBase64Image());
document.querySelector('#myImage').setAttribute('src', this.toBase64Image());
}
}
}
});
})
答案 0 :(得分:2)
基于这个问题,我创造了一个小提琴。我正在使用以下行删除图表。
animation: {
duration: 0,
onComplete: function(animation){
document.querySelector('#myChart').remove();
document.querySelector('#myImage').setAttribute('src', this.toBase64Image());
}
}
JSFiddle:here