Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I save chart as image without toolbox interaction in Echarts?

Tags:

echarts

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?

like image 608
cgat Avatar asked May 12 '17 21:05

cgat


2 Answers

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.

like image 119
Ovilia Avatar answered Sep 21 '22 08:09

Ovilia


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.

like image 24
Nitin Jadhav Avatar answered Sep 23 '22 08:09

Nitin Jadhav