Search code examples
javascriptchartsamcharts

amCharts - Get chart object by HTML Element or id?


I'm trying to access the chart methods of a chart (amCharts 3.21.14) that has already been instantiated and it's in the DOM being displayed, but I don't have a reference to it other than the element itself.

How can I do this? Couldn't find it in the docs.

Something like this :

const chart = AmCharts.getChart('#my-chart');
console.log(chart)

I couldn't find anytning similiar in the API reference

The reason I don't have access to the reference is because my code isn't the one that creates the chart, I'm working on a module that tries to export already existing charts.


Solution

  • I've found a workaround by searching for the ID in the AmCharts.charts list (although the documentation does not mentions this)