How can I get all Amchart instances of my page in Amchart V4, like it was this.AmChartsService.charts in V3? I want to export them all together.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can use the am4core.registry.baseSprites
array and use the native JavaScript methods to filter it.
Find by html id:
var id = 'chartdiv';
var chart = am4core.registry.baseSprites.find(c => c.htmlContainer.id === id);
Find by html class name:
var className = 'my-class';
var chart = am4core.registry.baseSprites.find(c => Array.from(c.htmlContainer.classList).includes(className));
Find by chart id:
var id = 'myId';
var chart = am4core.registry.baseSprites.find(c => c.id === id);