//需下载pdf,html2canvas 模块
savePDF:function(){
let obj1 = document.getElementById("pieChart");
let obj2 = document.getElementById("homepage-bandwidth-container");
let obj3 = document.getElementById("homepage-iops-container");
let obj4 = document.getElementById("homepage-await-container");
let arr1 = [];
arr1.push(obj1);
arr1.push(obj2);
arr1.push(obj3);
arr1.push(obj4);
let pdf = new JSPDF('', 'pt','a4');
for(let i = 0; i< arr1.length; i ++){
html2canvas(arr1[i]).then((canvas) => {
let pagedata = canvas.toDataURL("image/jpeg",1.0);
let contentWidth = canvas.width;
let contentHeight = canvas.height;
let imgWidth = 555.28;
let imgHeight = 555.28/contentWidth * contentHeight;
let position = 200;
pdf.addImage(pagedata, 'JPEG',0, position, imgWidth, imgHeight);
if( i<arr1.length ){
pdf.addPage(1);
}
if(i == arr1.length){
pdf.save('图表导出'.pdf')
}
});
}
},
标签:canvas,图表,getElementById,let,arr1,push,pdf,document,echarts From: https://blog.51cto.com/u_16071543/6192243