基于 echarts 实现同心圆占比图 - vue

template:

<div class="echartOne" id="mychartOne" :style="{ float: 'left', width: '50%', height: '57%' }"></div>

js:

//npm 安装后引入 echarts
import * as echarts from 'echarts';


//
mounted() {
        this.makeUpEcharts(1, 40, 'mychartOne', '白词占比', 'rgb(119,193,241)')
        this.makeUpEcharts(1, 20, 'mychartTwo', '黑词占比', 'rgb(236,100,92)')
    },

//
methods: {
makeUpEcharts(el, makeUp_val, id, ratio, background) {
        let color = ['#EAF1FF', '#73A0FA']; //圆环两色

        let echartData = [{
            value: makeUp_val,
            name: ratio,
            itemStyle: {
              color: background,
            },
            label: {
              show: true,
              fontSize: '15',
              fontWeight: 'bold',
              // formatter: '{b}\n\n{d}%',
              position: 'center',
              color: 'rgb(162,162,162)',
            },
          },
          {
            value: 100 - makeUp_val,
            name: '',
            itemStyle: {
              color: 'rgba(238,238,238)',
            },
            label: {
              show: false,
              fontSize: '16',
              fontWeight: 'bold',
              formatter: '{b}\n\n{d}%',
              position: 'center'
            },
          },

        ];


        var option = {

          color: color,
          series: [{
            type: 'pie',
            radius: ['60%', '90%'], //控制圆环大小
            center: ['50%', '50%'], //控制圆环位置
            data: echartData,
            hoverAnimation: false,
            itemStyle: {
              normal: {
                borderWidth: 2
              }
            },
            label: {
              show: true,
              fontSize: '16',
              fontWeight: 'bold',
              formatter: '{b}\n\n{d}%',
              position: 'center'
            },
          }]

        };
        let myChart = echarts.init(document.getElementById(id));
        myChart.setOption(option)
      },
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值