ehcarts实现分割圆环

如何使用echarts实现以下效果: 

思路:我们需要用echarts的饼状图结合echarts的仪表盘来实现,用仪表盘来分割圆环来实现如上效果。

完整代码如下所示:

 //设置饼状图颜色
      const color = new echarts.graphic.LinearGradient(0, 0, 1, 0, [
        {
          offset: 0,
          color: '#A0E5FF', // 0% 处的颜色
        },
        {
          offset:0.05,
          color:'#84DDFF'
        },
        {
          offset:0.13,
          color:'#61D3FF'
        },
        {
          offset:0.22,
          color:'#42CBFF'
        },
        {
          offset:0.31,
          color:'#2AC4FF'
        },
        {
          offset:0.41,
          color:'#17BFFF'
        },
        {
          offset:0.54,
          color:'#0ABBFF'
        },
        {
          offset:0.69,
          color:'#02B9FF'
        },
        {
          offset: 1,
          color: '#00B9FF', // 100% 处的颜色
        },
      ]);
      Bin.setOption({
        //设置中心文字和样式
        title:{
          text: '{rate|98%}\n{name|总好评率}',
          x: 'center',
          y: 'center',
          textStyle:{
            rich:{
              rate:{
                fontSize:32,
                color:'#02D9FD'
              },
              name:{
                fontSize:14,
                color:'#99C6E6'
              }
            }
          }
        },
        //环形图
        series: [  {
          type: 'pie',
          radius: ['90%', '77%'],
          silent: true,
          clockwise: true,
          startAngle: 90,
          z: 0,
          zlevel: 0,
          label: {
            normal: {
              position: "center",

            }
          },
          data: [{
            value: state.value,
            name: "",
            itemStyle: {
              normal: {
                color:color,
              }
            }
          },
            {
              value: 100-state.value,
              name: "",
              label: {
                normal: {
                  show: false
                }
              },
              itemStyle: {
                normal: {
                  color: "#005399"
                }
              }
            }
          ]
        },
          //仪表盘
          {
            name: "",
            type: "gauge",
            radius: "90%",
            center: ['50%', '50%'],
            startAngle: 90,
            endAngle:-269.9999,
            splitNumber: 60,
            hoverAnimation: true,
            axisTick: {
              show: false
            },
            splitLine: {
              length: -20,
              lineStyle: {
                width: 5,
                color: "#062340"
              }
            },
            axisLabel: {
              show: false
            },
            pointer: {
              show: false
            },
            axisLine: {
              lineStyle: {
                opacity: 0
              }
            },
            detail: {
              show: false
            },
            data: [{
              value: 0,
              name: ""
            }]
          },
        ]
      })

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 ECharts 5 中的 grid 和 graphic 组件来实现该需求。代码示例如下: ``` option = { grid: { left: 0, right: '50%', top: 'center', containLabel: true }, legend: { orient: 'vertical', left: '50%', top: 'center', itemGap: 48, data: ['数据1', '数据2', '数据3', '数据4'], }, graphic: [{ type: 'circle', shape: { cx: '25%', cy: '50%', r: 70, r0: 50 }, left: 'center', top: 'center', style: { fill: '#ccc' } }, { type: 'text', style: { text: '', font: '14px Microsoft YaHei' }, left: '25%', top: 'center' }], series: [{ name: '访问来源', type: 'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { show: false, position: 'center' }, emphasis: { label: { show: true, fontSize: '30', fontWeight: 'bold' } }, labelLine: { show: false }, data: [ {value: 335, name: '数据1'}, {value: 310, name: '数据2'}, {value: 234, name: '数据3'}, {value: 135, name: '数据4'} ] }] }; ``` 其中,grid 组件的 left 属性设置为 0,表示在左侧占据全部空间;right 属性设置为 '50%',表示在右侧占据一半的空间;top 属性设置为 'center',表示在垂直方向上居中对齐;containLabel 属性设置为 true,表示 grid 包含了图例,可以自动计算出图例的高度。legend 组件的 left 属性设置为 '50%',表示在右侧占据一半的空间;itemGap 属性设置为 48,表示 legend 与之间的距离为 48px。graphic 组件中的 type 为 circle,shape 中的 r 和 r0 分别表示的外半径和内半径;type 为 text,style 中的 text 表示文本内容,left 和 top 分别表示文本的水平和垂直位置。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值