温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

react如何增加echarts饼图

发布时间:2023-01-03 10:35:05 来源:亿速云 阅读:89 作者:iii 栏目:web开发

这篇“react如何增加echarts饼图”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“react如何增加echarts饼图”文章吧。

react项目增加echarts饼图的方法:1、通过“npm install echarts --save”命令安装“echarts”;2、使用import引入“echarts/lib/echarts”;3、通过“componentDidMount() {...}”实现增加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(
        <div className="huan"></div>
	)}

四、结果
react如何增加echarts饼图

以上就是关于“react如何增加echarts饼图”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI