echarts實現環形圖


 
//來自一個大佬的恩賜
var pass_rate = 70,average = 60,total = 100;
option = {
        tooltip: {
            show:false,
            trigger: 'item',
            formatter: "{a} : {c} ({d}%)"
        },
        //  color: ['#85b6b2', '#6d4f8d'],
         color: ['rgb(255,159,127)', 'rgb(50,197,233)'],
         legend: {
            orient: 'vertical',
            x: '35%',
            top:'27%',
            itemHeight: 10,//圖例的高度
            itemGap:8,//圖例之間的間距 
            data:['通過率'+pass_rate+'%','平均值'+average+'%']
            //圖例的名字需要和餅圖的name一致,才會顯示圖例
        },
        series: [
            {
                name:'通過率'+pass_rate+'%',
                type:'pie',
                radius: ['40%', '45%'],
                //環的位置
                label: {
                   show: false,
                   position: 'center',
                    // normal: { // 顯示的位置
                    //     position: 'inner'
                    // }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        fontSize: '20',
                        fontWeight: 'bold'
                    }
                },
                data:[
                    {
                      value:pass_rate, //需要顯示的數據
                      name: '通過率'+pass_rate+'%',
                      itemStyle: {
                        normal: {
                         color: 'rgb(255,159,127)'
                        }
                      }
                    },
                    {
                      value:total-pass_rate, 
                      //不需要顯示的數據,顏色設置成和背景一樣
                      itemStyle: {
                        normal: {
                         color: 'transparent'
                        }
                      }
                   }
                ]
            },
            {
                name:'平均值'+average+'%',
                type:'pie',
                radius: ['30%', '35%'],
                label: {
                   show: false,
                   position: 'center',
                    // normal: {
                    //     position: 'inner'
                    // }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        fontSize: '20',
                        fontWeight: 'bold'
                    }
                },
                data:[
                    {   name:'平均值'+average+'%',
                        value:average, 
                        itemStyle: {
                            normal: {
                             color: 'rgb(50,197,233)'
                            }
                        } 
                    },
                   {
                        value:total-average, 
                        itemStyle: {
                            normal: {
                                color: 'transparent'
                            }
                         }
                   }
                ]
            }
        ]
    };

  

樣式圖例:
                 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM