Echarts饼图3.0(渐变双层圆环)

代码:

const item = {
    value: 0.75,
    status: '这是我的标签',
    name: '这是我的名称'
}

option = {
    angleAxis: {
      max: 100,
      clockwise: false,
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        show: false
      },
      splitLine: {
        show: false
      }
    },
    radiusAxis: {
      type: 'category',
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        show: false
      },
      splitLine: {
        show: false
      }
    },
    polar: {
      center: ['50%', '50%'],
      radius: '188%'
    },
    series: [
      { // 绘制最外侧灰色的圆弧
        z: 1,
        type: 'pie',
        radius: ['98%', '90%'],
        center: ['50%', '50%'],
        data: [{
          value: 0,
          itemStyle: {
            normal: {
              color: '#eee'
            }
          },
          label: {
            show: false
          },
          labelLine: {
            normal: {
              smooth: true,
              lineStyle: {
                width: 0
              }
            }
          },
          hoverAnimation: false
        },
        {
          label: {
            show: false
          },
          labelLine: {
            normal: {
              smooth: true,
              lineStyle: {
                width: 0
              }
            }
          },
          value: 100 - Math.floor((Math.abs(item.value) * 100)),
          hoverAnimation: false,
          itemStyle: {
            color: '#eee',
            emphasis: { // 鼠标移入不高亮
              color: '#eee'
            }
          }
        }
        ]
      },
      { // 绘制最外侧白色的圆
        type: 'pie',
        z: 3,
        center: ['50%', '50%'],
        radius: ['90%', '0%'],
        data: [{
          label: {
            show: false
          },
          labelLine: {
            normal: {
              smooth: true,
              lineStyle: {
                width: 0
              }
            }
          },
          value: 0,
          hoverAnimation: false,
          itemStyle: {
            color: '#fff',
            shadowOffsetY: 3,
            shadowColor: 'rgba(0, 0, 0, 0.1)',
            shadowBlur: 10,
            emphasis: { // 鼠标移入不高亮
              color: '#fff'
            }
          }
        }]
      },
      { // 绘制最里侧白色的圆
        type: 'pie',
        z: 4,
        center: ['50%', '50%'],
        radius: ['50%', '0%'],
        data: [{
          label: {
            show: true,
            formatter: [`{b|${item.name}}`, `{d|}`, `{a|${item.value !== '--' ? (Math.abs(item.value) * 100).toFixed(2) + '%' : '--'}}`,  `{c|${item.status}}`].join('\n'),
            position: 'center',
            rich: {
              a: {
                fontSize: 72,
                color: '#ee011c',
                textAlign: 'center',
                padding: [0, 0, 12, 0]
              },
              b: {
                fontSize: 36,
                color: '#999',
                padding: [0, 0, 12, 0]
              },
              c: {
                padding: [8, 6, 6, 6],
                backgroundColor: 'rgba(74,144,226,0.5)',
                fontSize: 20,
                color: '#fff'
              }
            }
          },
          labelLine: {
            normal: {
              smooth: true,
              lineStyle: {
                width: 0
              }
            }
          },
          value: 0,
          hoverAnimation: false,
          itemStyle: {
            color: '#fff',
            shadowOffsetY: 3,
            shadowColor: 'rgba(0, 0, 0, 0.1)',
            shadowBlur: 10,
            emphasis: { // 鼠标移入不高亮
              color: '#fff'
            }
          }
        }]
      },
      { // 绘制最外侧带颜色的圆弧
        z: 2,
        type: 'bar',
        roundCap: true,
        data: [{
          value: (Math.abs(item.value) * 100),
          itemStyle: {
            normal: {
              shadowOffsetY: 2,
              shadowColor: 'rgba(0, 0, 0, 0.39)',
              shadowBlur: 10,
              color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0, color: '#ee011c' // color at 0% position
                    }, {
                        offset: 1, color: '#4a90e2' // color at 100% position
                    }],
                    global: false // false by default
                }
            }
          }
        }],
        coordinateSystem: 'polar',
        barWidth: 30
      }
    ]
  }

最终的效果:

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现echarts圆环的嵌套,可以使用多个饼图(圆)并为它们分别设置不同的样式。具体实现要根据项目需求进行配置。首先,你需要安装echartsecharts-for-react库。可以使用yarn或npm命令进行安装,比如"yarn add echarts echarts-for-react"或"npm install --save echarts echarts-for-react"。然后,你可以在React组件中引入echarts并使用ReactEcharts组件来渲染图表。你可以按照以下步骤进行操作: 1. 在组件中导入React和ReactEcharts: ```javascript import React from 'react'; import ReactEcharts from 'echarts-for-react'; ``` 2. 在组件中定义一个获取图表配置的方法,例如getOption方法: ```javascript getOption = () => { let option = { tooltip: { trigger: 'item' }, legend: { top: '5%', left: 'center' }, series: [{ name: 'Access From', type: 'pie', radius: ['40%', '70%'], avoidLabelOverlap: false, label: { show: false, position: 'center' }, emphasis: { label: { show: true, fontSize: '40', fontWeight: 'bold' } }, labelLine: { show: false }, data: [ { value: 1048, name: 'Search Engine' }, { value: 735, name: 'Direct' }, { value: 580, name: 'Email' }, { value: 484, name: 'Union Ads' }, { value: 300, name: 'Video Ads' } ] }] }; return option; } ``` 3. 在render方法中使用ReactEcharts组件渲染图表: ```javascript render() { return ( <div className='wrapper'> <ReactEcharts option={this.getOption()} style={{ height: '400px' }} /> </div> ); } ``` 这样就可以实现一个echarts圆环嵌套的图表了。具体的样式和配置可以根据需求进行调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值