【前端可视化】Echarts 实现环形饼图外层带阴影效果配置

效果展示

image

实现代码

原理主要还是用两个饼图嵌套,外侧做阴影,内层放数据。配置比较复杂,怕下次遇到就做个记录吧。

initEcharts() {
        const myChart = echarts.init(this.$refs.chart)
        const userScore = this.userScore.slice(0, this.userScore.length - 1)
        let option = {
          tooltip: {
            trigger: 'item',
            renderMode: 'html',
            formatter: "<div style='color: #000000;font-style: normal;font-weight: 500;font-size: 13PX;line-height: 18PX;'>{b0}</div><div style='color: #0a9391;margin-top:10PX;'>Score +{c0}%</div>",
            borderColor: '#fff',
            padding: 12,
            extraCssText: 'box-shadow: 0PX 2PX 4PX rgba(0, 0, 0, 0.25);',
          },
          legend: {
            show: false,
          },
          title: [{
            text: `{a|Your Score}\n{b|${userScore}}{c|%}`,
            top: 'center',
            left: 'center',
            textStyle: {
              fontFamily: 'PingFang SC',
              fontStyle: 'normal',
              fontWeight: 500,
              rich: {
                a: {
                  color: '#47bfaf',
                  padding: [0, 0, 10, 0],
                  fontSize: 13,
                },
                b: {
                  color: '#47bfaf',
                  fontSize: 40,
                },
                c: {
                  color: '#47bfaf',
                  fontSize: 18,
                },
              },
            },
          }, ],
          series: [{
              name: 'border',
              type: 'pie',
              clockWise: false,
              radius: '75%',
              center: ['50%', '50%'],
              animation: false,
              data: [{
                value: 0,
                color: '#fff',
                label: {
                  show: false,
                },
                labelLine: {
                  show: false,
                },
                emphasis: {
                  disabled: true,
                },
                select: {
                  disabled: true,
                },
                tooltip: {
                  show: false,
                },
                itemStyle: {
                  color: '#fff',
                  shadowColor: 'rgba(0, 0, 0, 0.2)',
                  shadowBlur: 15,
                  shadowOffsetX: 2,
                  shadowOffsetY: 2,
                },
              }, ],
            },
            {
              name: '',
              type: 'pie',
              radius: ['35%', '65%'],
              center: ['50%', '50%'],
              avoidLabelOverlap: false,
              selectedMode: false,
              select: {
                itemStyle: {
                  color: '#f9b762',
                },
              },
              itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2,
                emphasis: {
                  color: '#f9b762',
                },
                borderRadius: 7,
              },
              label: {
                show: false,
                position: 'center',
              },
              emphasis: {
                label: {
                  show: false,
                },
              },
              labelLine: {
                show: false,
              },
              data: this.echartsData,
            },
          ],
        }
        option && myChart.setOption(option)
      },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值