简体   繁体   中英

How can I get access to a Apache ECharts through id of DOM-Container?

I draw many piecharts on the map, at some point in time I need to update those piecharts using setOption . All I found they suggest saving the echart object inside the variable then update base on variables like below:

//Create
let echartsObj = echarts.init(document.getElementById("someId"));
    ...
};
//Update
echartsObj.setOption(option)

But this is not working for me because I have many echart instances and I should match them base on their id like below:

//It is not updating but I want something like that for updating echarts
someFunctionOrInstance("#echartId").setOption(option)

As I know, this approach is doable with other chart libraries like chart.js

setOption is a method of the object that echarts.init returned, but $("#echartId") returns a jQuery instance.

One option would be to store these into an object, using the ID as key - then you have easy access to them, directly via that.

The other would be to use theecharts.getInstanceByDom method - that does not select by ID directly, but needs to get a div or canvas element passed in, and will then return the correct instance for that element.

window.echartid.setOption(option)

this will do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM