amcharts / amcharts3-react

Official amCharts V3 React component
Apache License 2.0
118 stars 50 forks source link

AmMaps - access to the map object? #48

Closed awwester closed 7 years ago

awwester commented 7 years ago

I'm struggling to figure out how I can call the validateNow against the map object function. It's straightforward with normal javascript, but in the scope of this react package I'm not finding any examples of how to do this or if it's possible to access the actual chart/map instance.

class Map extends Component {
  constructor(props) {
    this.state = {
    mapstyle: {
    width: '100%',
    height: '450px'
    },
    mapConfig: {
    type: "map",
    theme: "light",
    dataProvider: this.continentsDataProvider,
    listeners: ...
      },
      chart: {}
    }
  }

  continentsDataProvider = { ... }
  someOtherDataProvider = { ... }

  ...

  render() {
    return (
      <div className="map" style={this.state.mapstyle}>
        <AmCharts.React {...this.state.mapConfig} />
      </div>
    )
  }
}
Pauan commented 7 years ago

@awwester It's not necessary to call validateNow: it will automatically be called when you make changes to the chart configuration.

If you want to access the chart object for some other reason, you can listen to the init event:

"listeners": [{
  "event": "init",
  "method": (e) => {
    var chart = e.chart;
    // Use chart methods here
  }
}]

You can also store the chart object in your class and then call it later:

"listeners": [{
  "event": "init",
  "method": (e) => {
    this.chart = e.chart;
  }
}]
if (this.chart) {
  this.chart.zoomOut();
}