ggregoire commented on issue #7763:
URL: https://github.com/apache/echarts/issues/7763#issuecomment-2898696843
If anyone interested:
```typescript
import type { ECharts } from 'echarts'
function convertSVGDataURLtoPNGDataURL(SVGDataURL: string): Promise<string> {
return new Promise(resolve => {
const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')!
const image = new Image()
image.addEventListener(
'load',
() => {
canvas.width = image.width
canvas.height = image.height
context.fillStyle = '#fff'
context.fillRect(0, 0, canvas.width, canvas.height)
context.drawImage(image, 0, 0, canvas.width, canvas.height)
resolve(canvas.toDataURL('image/png'))
},
false,
)
image.src = SVGDataURL
})
}
export function downloadSVGChartAsPNG(
echartsInstance: ECharts | undefined,
filename: string,
) {
if (!echartsInstance) return
const url = echartsInstance.getDataURL({
type: 'svg',
pixelRatio: 2,
backgroundColor: '#fff',
})
convertSVGDataURLtoPNGDataURL(url).then(PNGDataURL => {
const link = document.createElement('a')
link.href = PNGDataURL
link.download = filename
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]