react echarts

2019-11-02  本文已影响0人  SugeonYen
constructor(props){
    super(props)
    this.state = {}
}

componentDidMount() {
    //put 官网实例option前面同级代码
    
    // 基于准备好的dom,初始化echarts实例
    this.myChart = echarts.init(document.getElementById(this.props.id));
    // 绘制图表
    this.myChart .setOption({
    //官网实例option下面代码
    });
    window.addEventListener('resize', this.resize);
}

resize = () => {
    this.myChart.resize();
}

componentWillUnmount() {
    window.removeEventListener('resize', this.resize);
}

render() {
    return (
        <div id={this.props.id}  style={{height: '24px'}}></div>
    );
}

6.从官网拉入代码
把官网实例中option = {}中的代码拉到 this.myChart .setOption()中间,其他声明放到 componentDidMount() {}下面
上一篇 下一篇

猜你喜欢

热点阅读