Gerrie van Wyk Gerrie van Wyk - 1 month ago 29
React JSX Question

How to envoke a method on a react component (Amcharts-React)

Is there a way to evoke a method on a chart. Such as:

chart.zoomOut()


I'm struggling to find a handle for the chart object.
To render the chart i use:

<AmCharts ref={`chart_${this.props.tileid}`} {...this.chart} dataProvider={this.props.data} />


https://github.com/amcharts/amcharts3-react

I tried to inspect the element to see if I can access these methods through:

ch = this.refs[`chart_${this.props.tileid}`]


However in the 'ch' object I can not seem to find any of the methods mentioned in:
https://docs.amcharts.com/3/javascriptcharts/AmSerialChart#zoomOut

How would one reference a element to evoke a method on it?

Answer

The amchart3-react component sets the chart as a state. Thus the method can be evoked by calling:

this.refs.chartref.state.chart.zoomOut();