温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用Echarts实现多段圆环图

发布时间:2022-03-03 14:06:13 来源:亿速云 阅读:621 作者:iii 栏目:开发技术

这篇文章主要介绍“怎么用Echarts实现多段圆环图”,在日常操作中,相信很多人在怎么用Echarts实现多段圆环图问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用Echarts实现多段圆环图”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

完美实现

最终在玫瑰图的网站上找到一个比较复杂的实现,通过修改各项配置基本完美的使用ehcarts实现了这个图形. 首先是echarts的一个option的配置代码,为了方便将series与option做了一个分离

const colorDataHandle = (data, total, width = 375) => {
    let num = 0
    let option = {
        angleAxis: {
            axisLine: {
		show: false,
            },
            axisLabel: {
		show: false,
            },
            splitLine: {
		show: false,
            },
            axisTick: {
		show: false,
            },
            min: 'dataMin',
            max: 'dataMax',
            startAngle: 135,
            },
            radiusAxis: {
                type: 'category',
                axisLine: {
                    show: false,
            },
            axisTick: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
        },
        polar: {
            radius: '95%'
        },
        series: []
      }
      // option是对传入的数据的一个处理
      const options = data.map((item, index) => {
        num += item
        const a = {
          type: 'bar',
          data: [0, 0, 0, num],
          coordinateSystem: 'polar',
          z: 9999 - index,
          roundCap: true,
          color: colors[index],
          barGap: '-100%',
          // barWidth: '30%',
          itemStyle: {
            // 控制弧的宽,弧的宽的控制并没有做太多的情况判断,简单的区分了一下
            borderWidth: index === 0 ? 4 : index === 1 ? 2 : 0,
            // shadowBlur: 5,
            // color: 'transparent',
            borderColor: colors[index],
            shadowColor: colors[index],
          },
        }
        return a
      })
            option.series = options
      return option
}

然后是对3种颜色区域的一个处理

const colors = [
  {
    type: 'linear',
    x: 0,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [
      {
        offset: 0,
        color: '#1DBC3F', // 0% 处的颜色
      },
      {
        offset: 1,
        color: '#1DBC3F', // 100% 处的颜色
      },
    ],
  },
  {
    type: 'linear',
    x: 0,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [
      {
        offset: 0,
        color: '#CB3939', // 0% 处的颜色
      },
      {
        offset: 1,
        color: '#CB3939', // 100% 处的颜色
      },
    ],
  },
  {
    type: 'linear',
    x: 0,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [
      {
        offset: 0,
        color: '#C0C0C0', // 0% 处的颜色
      },
      {
        offset: 1,
        color: '#C0C0C0', // 100% 处的颜色
      },
    ],
  },
];

这里是灵活使用了echarts type为linear的组件,具体的一个配置项是怎么实现我并没有深入探究.

效果图

最终实现的一个效果图在真机上的展示

怎么用Echarts实现多段圆环图

既保证了每段弧的首尾的圆角的问题,也实现了每段弧宽的增加

到此,关于“怎么用Echarts实现多段圆环图”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI