美文网首页
react echarts

react echarts

作者: SugeonYen | 来源:发表于2019-11-02 16:39 被阅读0次
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() {}下面

相关文章

网友评论

      本文标题:react echarts

      本文链接:https://www.haomeiwen.com/subject/eqiquctx.html