Search code examples
amcharts

Amchart V4 export all existing amcharts together in a page


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.


Solution

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