调用:
this.handleMenuClick('png','.chart-plate-card-body')"
this.handleMenuClick('jpg','.chart-plate-card-body')"
方法:
getChartSVG (val) {
return this.chart.getSVG(val)
},
downloadImg (type, parClass) {
const img = new Image()
let target
let svg
const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
if (parClass === 'default') {
img.src = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(this.getChartSVG({ chart: { width: 1920, height: 838 } }))))} `
canvas.width = 1920
canvas.height = 838
} else {
img.src = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(this.getChartSVG({ chart: { width: this.chart.chartWidth, height: this.chart.chartHeight } }))))} `
canvas.width = this.chart.chartWidth
canvas.height = this.chart.chartHeight
}
const _this = this
img.onload = function () {
context.drawImage(img, 0, 0)
const imgEle = new Image()
const url = canvas.toDataURL(`image/${type}`)
imgEle.src = url
imgEle.onload = function () {
const a = document.createElement('a')
a.href = url
a.download = _this.chartTitle || _this.downloadTitle
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
}
}
}