react项目增加echarts饼图的方法:1、通过“npm install echarts –save”命令安装“echarts”;2、使用import引入“echarts/lib/echarts”;3、通过“componentDidMount() {…}”实现增加echarts饼图即可。
本教程操作环境:Windows10系统、react18.0.0版、Dell G3电脑。
react项目怎么增加echarts饼图?
在React项目中使用echarts饼状图
一、安装
npm install echarts --save
登录后复制
二、引入
import echarts from 'echarts/lib/echarts';import 'echarts/lib/chart/pie'; //饼状图import 'echarts/lib/component/tooltip';import 'echarts/lib/component/title';import 'echarts/lib/component/legend'import 'echarts/lib/component/markPoint'
登录后复制
三、使用
componentDidMount() { //环形图百分比 var huan_val = document.getElementsByClassName("huan")[0]; var chart = echarts.init(huan_val); let option = { color: ["#f8e367", "#99dfff", "#58c0f0", "#5ea6ff", "#ff9e48", "#bcbcbc"], series: [{ name: "驾驶分析", type: "pie", radius: ['60%', '80%'], avoidLabelOverlap: false, label: { normal: { show: false, position: 'center' }, emphasis: { show: true, textStyle: { fontSize: '30', fontWeight: 'bold' } } }, labelLine: { normal: { show: false } }, data: [{ value: 33, name: '慢速' }, { value: 26, name: '低速' }, { value: 6, name: '中速' }, { value: 2, name: '高速' }, { value: 3, name: '超速' }, { value: 30, name: '怠速' }] }] }; chart.setOption(option); }
登录后复制
render(){return( )}
登录后复制
推荐学习:《react视频教程》
以上就是react项目怎么增加echarts饼图的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2922780.html