Echarts 环形进度条 环形图嵌套

11 篇文章 1 订阅

效果图如下
在这里插入图片描述
其他效果:
效果1:https://blog.csdn.net/weixin_41192581/article/details/104840199
效果2:https://www.cnblogs.com/myprogramer/p/12509764.html
渐变色详解:https://zhuanlan.zhihu.com/p/183893861

注意:
(1)最内层背景色、白色内框、进度条、外框,都是在 series 里设置 type为pie 的canvas
(2)最内层背景色 和 背景色上的文字用 z: 2zlevel: 100 提升层级
文字在graphic中设置
(3)阻止鼠标悬浮时区域弹出

hoverAnimation: false, //鼠标悬浮是否有区域弹出动画,false:无 true:有
avoidLabelOverlap: false,

(4)取消鼠标高亮效果
方法一:silent: true, //取消鼠标移入高亮效果: 不响应和触发鼠标事件

silent: true, //取消鼠标移入高亮效果: 不响应和触发鼠标事件

方法二:将hover时的颜色与正常颜色设置为相同

data: [
  {
    value: 100,
    itemStyle: {
      normal: {
        color: '#f5f5f5',
      },
      emphasis: { color: '#f5f5f5' }, // 取消鼠标移入高亮效果: 将hover时的颜色设置为相同
    },
  },
],

(5)设置进度条圆角

borderRadius: ['20%', '50%'], //进度条圆角: 当饼图为环形图时,内圆角半径是内圆半径的 20%、外圆角半径是外圆半径的 50%

(6)调整环形图在页面上距离页面左侧的距离:
设置 .chartBox
在这里插入图片描述

完整实现:

<template>
  <div class="chartBox">
    <div id="treeChart" :style="{ height: '242px' }"></div>
  </div>
</template>

<script>
export default {
  name: 'eCharts',
  data() {
    return {
      value: 60,
    }
  },
  mounted() {
    this.showChart()
  },
  methods: {
    showChart() {
      // 基于准备好的dom,初始化echarts实例
      var myChart = this.$echarts.init(document.getElementById('treeChart'))

      var value = 200 //当前进度
      var maxValue = 300 //进度条最大值
      var option = {
        legend: {
          orient: 'vertical',
          x: 'left',
        },
        graphic: [
          //第一行文字
          //内容 + 位置
          {
            type: 'text',
            left: 'center',
            top: '30%',
            z: 2,
            zlevel: 100,
            style: {
              text: '全省故障XX',
              textAlign: 'center',
              fill: '#333333',
              fontSize: 12,
            },
          },
          {
            type: 'text',
            left: 'center',
            top: '36.5%',
            z: 2,
            zlevel: 100,
            style: {
              text: '解决率',
              textAlign: 'center',
              fill: '#333333',
              fontSize: 12,
            },
          },
          {
            type: 'text',
            left: 'center',
            top: '45%',
            z: 2,
            zlevel: 100,
            style: {
              text: '67%',
              textAlign: 'center',
              fontWeight: 'bold',
              fill: '#5393E7',
              fontSize: 22,
            },
          },
          {
            type: 'text',
            left: 'center',
            top: '58%',
            z: 2,
            zlevel: 100,
            style: {
              text: '200 / 300',
              textAlign: 'center',
              fill: '#333333',
              fontSize: 14,
            },
          },
          {
            type: 'text',
            left: 'center',
            top: '65.5%',
            z: 2,
            zlevel: 100,
            style: {
              text: '已解决 / 总数',
              textAlign: 'center',
              fill: '#333333',
              fontSize: 12,
            },
          },
        ],

        series: [
          // 最内层背景色
          {
            type: 'pie',
            radius: [0, '60%'],
            hoverAnimation: false, //取消鼠标悬浮放大的效果
            labelLine: {
              normal: {
                show: false,
              },
            },
            animation: false,
            data: [
              {
                value: 100,
                itemStyle: {
                  normal: {
                    color: '#f5f5f5',
                  },
                  emphasis: { color: '#f5f5f5' }, // 取消鼠标移入高亮效果: 将hover时的颜色设置为相同
                },
              },
            ],
          },
          // 内边框
          {
            type: 'pie',
            radius: ['60%', '61%'],
            labelLine: {
              normal: {
                show: false,
              },
            },
            hoverAnimation: false, //鼠标悬浮是否有区域弹出动画,false:无 true:有
            avoidLabelOverlap: false,
            animationEasing: 'cubicOut',
            data: [
              {
                value: this.value,
                itemStyle: {
                  color: '#fff',
                },
              },
            ],
          },
          // 进度条
          {
            type: 'pie',
            radius: ['62%', '73%'],
            itemStyle: {
              normal: {
                color: '#6a5acd',
              },
            },
            labelLine: {
              normal: {
                show: false,
              },
            },
            hoverAnimation: false, //鼠标悬浮是否有区域弹出动画,false:无 true:有
            avoidLabelOverlap: false,
            silent: true, //取消鼠标移入高亮效果: 不响应和触发鼠标事件
            animationEasing: 'cubicOut',
            data: [
              //value当前进度 + 颜色
              {
                value: value,
                itemStyle: {
                  //渐变颜色
                  color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      {
                        offset: 0,
                        color: '#C9FFCB', // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: '#2C87FF', // 100% 处的颜色
                      },
                    ],
                    global: false, // 缺省为 false
                  },
                  borderRadius: ['20%', '50%'], //进度条圆角: 当饼图为环形图时,内圆角半径是内圆半径的 20%、外圆角半径是外圆半径的 50%
                },
              },
              //(maxValue进度条最大值 - value当前进度) + 颜色
              {
                value: maxValue - value,
                itemStyle: {
                  // 线性渐变颜色
                  // color: {
                  //   type: 'linear',
                  //   x: 0,
                  //   y: 0,
                  //   x2: 0,
                  //   y2: 1,
                  //   colorStops: [
                  //     {
                  //       offset: 0,
                  //       color: '#FCFCFC', // 0% 处的颜色
                  //     },
                  //     {
                  //       offset: 1,
                  //       color: '#F7F7F7', // 100% 处的颜色
                  //     },
                  //   ],
                  //   global: false, // 缺省为 false
                  // },
                  // 径向渐变颜色
                  color: {
                    type: 'radial',
                    x: 1,
                    y: 1,
                    r: 1,
                    colorStops: [
                      {
                        offset: 0,
                        color: '#FCFCFC', // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: '#F7F7F7', // 100% 处的颜色
                      },
                    ],
                    global: false, // 缺省为 false
                  },
                },
              },
            ],
          },
          // 外框
          {
            type: 'pie',
            radius: ['73%', '83%'],
            itemStyle: {
              // 阴影
              shadowBlur: 12,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.1)',
            },
            labelLine: {
              normal: {
                show: false,
              },
            },
            hoverAnimation: false,
            animationEasing: 'cubicOut',
            data: [
              {
                value: this.value,
                itemStyle: {
                  color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                    {
                      offset: 0,
                      color: '#F7F7F7',
                    },
                    {
                      offset: 1,
                      color: '#FCFCFC',
                    },
                  ]),
                },
              },
            ],
          },
        ],
      }

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option)
      //随着浏览器窗口大小改变而改变
      window.addEventListener('resize', function () {
        myChart.resize()
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.chartBox {
  width: 50%;
  position: relative;
}
</style>

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Windyluna

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值