amcharts3-react icon indicating copy to clipboard operation
amcharts3-react copied to clipboard

Custom ID to AmCharts

Open aranderia15 opened this issue 5 years ago • 1 comments

By default, the charts created have the id in this format - AmCharts_React_1

Can we give custom defined id's to the charts? If yes, then how?

Please let me know. Thanks!

aranderia15 avatar Mar 14 '19 19:03 aranderia15

Currently the IDs start from 1 as you can see here.

The ID pattern is hard coded which is not good when having two different React apps on the same screen for example. They would both start their IDs with __AmCharts_React_1__. That's not good since IDs should be unique and it breaks the chart functionality.

I propose an optional prop idPrefix which would then be used for the generation of IDs and serve as namespacing. The fallback prefix would still be __AmCharts_React_.

i.e.:

<Amcharts.React idPrefix="__MyAmCharts_">

Would then be used like

AmCharts.React = React.createClass({
    getInitialState: function () {
      return {
        id: (this.props.idPrefix || "__AmCharts_React_") + (++id) + "__",
        chart: null
      };
    },

I'm happy to create a PR if you agree.

xbojch avatar May 13 '19 09:05 xbojch