I'd like to save an echart as an image. If the toolbox.saveAsImage
option is set to true
, I can use a toolbox action to save the chart. However, I'm wondering if this can be done programmatically?
This should be achieved by echartsInstance.getDataURL
, with which you can set image format, pixel ratio and so on.
(opts: {
// Exporting format, can be either png, or jpeg
type?: string,
// Resolution ratio of exporting image, 1 by default.
pixelRatio?: number,
// Background color of exporting image, use backgroundColor in option by default.
backgroundColor?: string,
// Excluded components list. e.g. ['toolbox']
excludeComponents?: Array.<string>
}) => string
See ECharts doc for more information.
If you have echart instance variable, use getDataURL
method with params like this:
echartInstance.getDataURL({
pixelRatio: 2,
backgroundColor: '#fff'
});
Calling e.getDataURL()
without options won't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With