###点击图表的时候,data数据发生了变化,图表不能实时刷新?importReactfrom'react';import{Card}from'antd';importReactEchartsCorefrom'echarts-for-react/lib/core';importechartsfrom'echarts/lib/echarts';import'echarts/lib/chart/pie';echarts.registerTheme('myTheme',{backgroundColor:'rgb(15,55,95)'});exportdefaultclassBarextendsReact.Component{constructor(props){super(props);this.state={loadingChart:true,data:[{value:500,name:'Android'},{value:200,name:'IOS'},{value:360,name:'PC'},{value:100,name:'Ohter'}]}}onChartClick=()=>{constdata=this.state.data;data.push({value:Math.random()*100,name:'Other'+Math.random()});this.setState({data});}onChartLegendselectchanged=()=>{console.log(2)}//方法必须放在上面,不然找不到对应的方法onEvents={'click':this.onChartClick,'legendselectchanged':this.onChartLegendselectchanged}//获取配置getOption=()=>{constoption={title:{text:'ECharts数据统计'},lengend:{},series:[{name:'访问量',type:'pie',radius:'60%',data:this.state.data}]};returnoption;}//chartsloadReady后的回调模拟回调onChartReadyCallback=()=>{setTimeout(()=>{this.setState({loadingChart:false});},2000);}render(){return(){JSON.stringify(this.state.data)}
echarts={echarts} style={{height:'500px'}}className='noneClass'theme='light'onChartReady={this.onChartReadyCallback}option={this.getOption()}showLoading={this.state.loadingChart}onEvents={this.onEvents}lazyUpdate={(this.getOption(),false)}>}}
米脂
摇曳的蔷薇
相关分类