问题
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);
来源:https://stackoverflow.com/questions/54835456/amchart-v4-export-all-existing-amcharts-together-in-a-page