echarts实现圆环嵌套(多重环形图,连接处倒圆角!!!)

最近遇到一个需求,需要实现两个环嵌套,查了网上发现有很多圆环嵌套的实现方式,包括官网社区也能找到很多示例,但是需求是需要倒圆角的,找到的倒圆角的有但是,是那种鼠标移入后圆角看起来很诡异的,后来用bar实现了,效果如下图:

实现思路:

1、确定两个圆环的中心点

 polar: {
      center: ["51%", "40%"],
      radius: ["65%", "100%"],
    },

2、配置option

核心代码如下:


  const option = {
    backgroundColor: 'transparent', //背景颜色
    title: [
      {
        text: val.title,
        x: "center",
        top: "35%",
        textStyle: {
          color: "#fff",
          width: 100,
          fontSize: '1rem',
          lineHeight:14,
          fontWeight: "700",
          overflow: "breakAll",
          fontFamily:"MiSans-Bold"
        },
      },
    ],
    angleAxis: {  
      type: "value",
      min: 0,
      max: 100,
      startAngle: -60,//调整初始角度
      axisLine: {
        show: false,
      },
      axisTick: {
        show: false,
      },
      splitLine: {
        show: false,
      },
      axisLabel: {
        show: false,
      },
    },
    radiusAxis: {
      type: "category",
      data: ["圆环1", "圆环2"],
      z: 100,
      axisLine: {
        show: false,
      },
      axisTick: {
        show: false,
      },
      axisLabel: {
        show: false,
        margin: 6,
        fontSize: '1rem',
        color: "#96F5F6",
        interval: 0,
      },
    },
    polar: {
      center: ["51%", "40%"],
      radius: ["65%", "100%"],
    },
    tooltip: {
      show: true,
    },
    series: [
      {
        type: "bar",
        barWidth: "70%",
        data: [63],
        coordinateSystem: "polar",
        name: "圆环1",
        stack: "a",
        roundCap: true,
        itemStyle: {
          color: "rgb(255,0,0)",
          borderRadius: 5,
        },
        showBackground: true,
        backgroundStyle: {
          color: "rgba(45,75,116,0.1)",
        },
      },
      {
        type: "bar",
        data: [0, 78],
        coordinateSystem: "polar",
        name: "圆环2",
        stack: "a",
        roundCap: true,
        itemStyle: {
          color: "rgb(0,132,255)",
        },
        showBackground: true,
        backgroundStyle: {
          color: "rgba(45,75,116,0.5)",
        },
      },
    ],
    legend: {
      bottom: 1,
      orient: "vertical",
      icon: "rect",
      itemHeight: 8,
      itemWidth: 8,
      show: true,
      data: ["圆环1", "圆环2"],
      selectedMode: false,
      textStyle: {
        color: "#fff",
        fontSize: '1rem',
        fontFamily:"MiSans-Bold"
      },
    },
  };
   const dom = document.getElementById("myChart");
    const myChart = echarts.init(dom); // 初始化echarts实例
    myChart.setOption(option);
    chartInstances.push(myChart)

这是两个圆环嵌套的,如果想实现4个5个等多个圆环嵌套的话也是一样的,只是多一个数据而已。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值