amcharts3-react
amcharts3-react copied to clipboard
Custom ID to AmCharts
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!
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.