Amchart V4 export all existing amcharts together i

2019-08-09 16:50发布

问题:

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);


标签: amcharts