sam*_*360 3 javascript amcharts
有没有办法使用元素Id获取AmChart的实例?在编写通用API以使用AmCharts时,这非常有用.
<div id="myChart"></div>
<div id="myChart2"></div>
<script>
function makeChart(id, settings) {
var ins = AmCharts.getChart(id) ?? //need a way to find the instance
if (ins) ins.clear();
AmCharts.makeChart(id,settings);
}
</script>
Run Code Online (Sandbox Code Playgroud)
ger*_*ric 12
你可以像这样解决这个问题:
function getChart(id) {
var allCharts = AmCharts.charts;
for (var i = 0; i < allCharts.length; i++) {
if (id == allCharts[i].div.id) {
return allCharts[i];
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在只需调用getChart("myChart")它就会返回实例.
| 归档时间: |
|
| 查看次数: |
4327 次 |
| 最近记录: |