要将图例的位置设置为相对位置,可以使用百分比来设置图例的top和right属性,这样无论浏览器放大缩小,图例的位置都会相对移动。同时,设置legend的borderColor和borderWidth属性为0,可以将边框去除。

修改后的代码如下:

option: {
  tooltip: {
    trigger: 'item',
    formatter: '{a} <br/>{b} {d}%'
  },
  legend: {
    top: 'center',
    right: '5%',
    icon: 'circle',
    orient: 'vertical',
    textStyle: {
      fontSize: 10
    },
    borderColor: 'none',
    borderWidth: 0
  },
  series: [
    {
      name: '测试通过比例',
      type: 'pie',
      radius: ['60%', '50%'],
      center: ['40%', '50%'],
      avoidLabelOverlap: false,
      label: {
        show: false,
        position: 'center'
      },
      emphasis: {
        label: {
          show: false,
          fontSize: 20,
          fontWeight: 'bold'
        }
      },
      labelLine: {
        show: false
      },
      data: [
        {
          value: '',
          name: '通过',
          itemStyle: {
            color: '#4fd1c5'
          }
        },
        {
          value: '',
          name: '未通过',
          itemStyle: {
            color: '#ee6666'
          }
        },
        {
          value: '',
          name: '未执行',
          itemStyle: {
            color: '#fdc078'
          }
        }
      ]
    }
  ]
}

这样就将图例的位置设置为相对位置,并去除了边框

option 设置标签的显示格式 tooltip trigger item formatter a brb d legend top center right 5 将图例放置在右侧 icon circle orient ver

原文地址: http://www.cveoy.top/t/topic/ieXq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录