Reactjs 重置amchart3上的缩放在数据更新时作出反应
数据更新时如何重置图表缩放。我正在使用amcharts和react: 我正在用以下内容重新绘制图表:Reactjs 重置amchart3上的缩放在数据更新时作出反应,reactjs,amcharts,Reactjs,Amcharts,数据更新时如何重置图表缩放。我正在使用amcharts和react: 我正在用以下内容重新绘制图表: <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 className='row' id={this.props.tileid} style={{height: '80%', width: '100%'}} >
<AmCharts ref={`chart_${this.props.tileid}`} {...this.chart} dataProvider={this.props.data()} />
</div>
但是这没有效果
谢谢。为了实现这一点,我在react组件中添加了以下内容:
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,并将图形设置为缩小状态。为了实现这一点,我在react组件中添加了以下内容:
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都会被设置,图形也会被设置为缩小状态。您能解释一下为什么使用带括号的
dataProvider={This.props.data()}
?似乎无法将数据正确绑定到图表,但仅执行此数据函数一次。您能否解释一下为什么使用带括号的dataProvider={this.props.data()}
?这似乎无法将数据正确绑定到图表,但只执行此数据函数一次。