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
漫思
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用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 端网页特效