2016-10-19 28 views
1

如何在數據更新時重置圖表縮放。我使用amcharts和反應: https://github.com/amcharts/amcharts3-react重置數據更新時的縮放amchart3反應

我正在redering圖表有:

<div className='row' id={this.props.tileid} style={{height: '80%', width: '100%'}} > 
    <AmCharts ref={`chart_${this.props.tileid}`} {...this.chart} dataProvider={this.props.data()} /> 
</div> 

凡我數據道具切片包含/排除數據。數據包括數據在模具圖表中呈現,但圖表仍然放大到上一級別,用戶必須縮小才能看到所選數據。我只想讓縮放級別最大限度縮小數據更新。

我:

this.chart.zoomOutOnDataUpdate = true; 

但這並沒有影響..

感謝。

+0

你能解釋爲什麼在括號中使用'dataProvider = {this.props.data()}'嗎?似乎沒有將數據正確綁定到圖表,但只執行一次該數據功能。 –

回答

0

要做到這一點,我添加下面的反應組件:

componentWillReceiveProps(nextprops){ 
    if(this.props.data !== nextprops.data){ 
    this.setState({zoomoutflag: true}) 
    }else{ 
    this.setState({zoomoutflag: false}) 
    } 
    if(nextprops) 
    this.chart = this.initChart(nextprops); 
} 

componentDidUpdate(){ 
    if(this.refs.chartref && this.state.zoomoutflag){ 
    if(this.refs.chartref.state.chart){ 
     this.refs.chartref.state.chart.zoomOut(); 
    } 
    } 

}

這個工作很適合我,現在每天的數據是在我的情況下,通過更換過濾器更新時,zoomoutflag被設置並且圖形被設置爲縮小狀態。