简体   繁体   English

如何通过DOM-Container的id访问一个Apache的ECharts?

[英]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 .我在 map 上绘制了很多饼图,有时我需要使用setOption更新这些饼图。 All I found they suggest saving the echart object inside the variable then update base on variables like below:我发现他们建议将 echart object 保存在变量中,然后根据如下变量更新:

//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:但这对我不起作用,因为我有很多 echart 实例,我应该根据它们的id匹配它们,如下所示:

//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据我所知,这种方法适用于其他图表库,如chart.js

setOption is a method of the object that echarts.init returned, but $("#echartId") returns a jQuery instance. setOptionecharts.init返回的object的一个方法,但是$("#echartId")返回的是jQuery实例。

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.一种选择是将这些存储到 object 中,使用 ID 作为密钥 - 然后您可以直接通过它轻松访问它们。

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.另一种是使用echarts.getInstanceByDom方法 - 不是直接通过 ID select,而是需要获取传入的 div 或 canvas 元素,然后返回该元素的正确实例。

window.echartid.setOption(option)

this will do.这样就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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