react echarts的正确使用方式

复制代码
import React, { Component, createRef } from 'react'

import * as echarts from 'echarts';

export default class index extends Component<any, any> {
    ref = createRef<any>();
    myChart: any = null;
    render() {
        return (
            <div ref={this.ref} style={{  ...(this.props.style || {}) }}></div>
        )
    }

    componentDidMount(): void {
        var myChart = echarts.init(this.ref.current);
        // 绘制图表
        myChart.setOption(this.props.option);
        this.myChart = myChart;
    }


    componentDidUpdate(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void {
        console.log('componentDidUpdate');
        this.myChart.setOption(this.props.option);
    }
}
复制代码
  option: {
        title: {
          text: 'ECharts 入门示例'
        },
        tooltip: {},
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
          {
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      }
 
对于option的能力,应该使用 _.set 进行数据的merge

posted on   漫思  阅读(0)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2022-02-26 Windows2012R2配置SQLSERVER2012集群Alwayson配置高可用性
2022-02-26 【H5】十款构建 React.js 应用程序的UI框架
2022-02-26 Sql Server2008-读写分离
2022-02-26 Aforge.net之旅——开篇:从识别验证码开始
2022-02-26 AForge.NET
2022-02-26 移动端网页特效
2022-02-26 PC 端网页特效

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示