溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

react如何增加echarts餅圖

發(fā)布時(shí)間:2023-01-03 10:35:05 來源:億速云 閱讀:110 作者:iii 欄目:web開發(fā)

這篇“react如何增加echarts餅圖”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“react如何增加echarts餅圖”文章吧。

react項(xiàng)目增加echarts餅圖的方法:1、通過“npm install echarts --save”命令安裝“echarts”;2、使用import引入“echarts/lib/echarts”;3、通過“componentDidMount() {...}”實(shí)現(xiàn)增加echarts餅圖即可。

在React項(xiàng)目中使用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() {
       //環(huán)形圖百分比
       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>
	)}

四、結(jié)果
react如何增加echarts餅圖

以上就是關(guān)于“react如何增加echarts餅圖”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI