echarts 实现同一组legend控制两个饼图示例

实现同一组legend控制两个饼图示例:

该示例有如下几个特点:

        ①饼图不同值实现分割

        ②实现tooltip自定义样式(echarts 实现tooltip提示框样式自定义-CSDN博客

        ③自定义label内容

        ④不同值颜色渐变

代码如下:

this.options = {
  title: [
    {
      text: '保管专业',
      x: "center",
      y: "center",
      left: "49%",
      top: "23%",
      textAlign: "center",
      textStyle: {
        color: "#ffffffcc",
        fontSize: 16,
        fontWeight: "bold",
        align: "center",
      },
    },
    {
      text: '救生专业',
      x: "center",
      y: "center",
      left: "49%",
      top: "73%",
      textAlign: "center",
      textStyle: {
        color: "#ffffffcc",
        fontSize: 16,
        fontWeight: "bold",
        align: "center",
      },
    },
  ],
  tooltip: {
    trigger: 'item',
    textStyle: {
      align: "left",
    },
    className: 'custom-tooltip-box',
    formatter: function(params) {
      return `<div class='custom-tooltip-style'>
        <span>${airportName} ${params.seriesName}</span></br>
        <div class="span">
          <span>${params.name}</span>
          <span>${params.value} 人</span>
        </div>
      </div>`
    },
  },
  legend: {
    orient: "vertical",
    // top: "40%",
    left: "2%",
    top:"2%",
    align: "left",
    textStyle: {
      color: "#C7F1FF",
      fontSize: 16
    },
    itemWidth: 15,
    itemHeight: 15,
    data: ["军官", "军士", "义务兵"]
  },
  color: this.colors,
  series: [
    {
      name: '保管专业',
      type: 'pie',
      radius: ['18%', '30%'],
      center: ['50%', '25%'],
      avoidLabelOverlap: false,
      labelLine: {
        normal: {
          length: 20,
          length2: 120,
          lineStyle: {
            width: 1,
          },
        },
      },
      label: {
        show: true,
        position: "outside",
        padding: [0, -70, 25, -100],
        edgeDistance: 5,
        textStyle: {
          color: "#ffffff",
          fontSize: 16,
        },
        formatter: (params) => {
          return params.name + " " + "{percent|" + params.percent.toFixed(0) + "%}";
        },
        rich: {
          hr: {
            borderRadius: 3,
            width: 3,
            height: 3,
          },
          a: {},
        },
      },
      itemStyle: {
        borderWidth: 8,
        borderColor: "#113a75"
      },
      data: this.echartData1
    },
    {
      name: '救生专业',
      type: 'pie',
      radius: ['18%', '30%'],
      center: ['50%', '75%'],
      avoidLabelOverlap: false,
      labelLine: {
        normal: {
          length: 20,
          length2: 120,
          lineStyle: {
            width: 1,
          },
        },
      },
      label: {
        show: true,
        position: "outside",
        padding: [0, -70, 25, -100],
        edgeDistance: 5,
        textStyle: {
          color: "#ffffff",
          fontSize: 16,
        },
        formatter: (params) => {
          return params.name + " " + "{percent|" + params.percent.toFixed(0) + "%}";
        },
        rich: {
          hr: {
            borderRadius: 3,
            width: 3,
            height: 3,
          },
          a: {},
        },
      },
      itemStyle: {
        borderWidth: 8,
        borderColor: "#113a75"
      },
      data: this.echartData2
    }
  ]
}

效果图如下:

该示例中的属性可在官网中查阅,若有其他疑问可私信留言互相交流学习~

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

超级无敌小小小白

感谢老板的打赏~^v^~

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

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

打赏作者

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

抵扣说明:

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

余额充值