echartData.js 2.37 KB
const pieOptions = {
  title: {
    show: true, //显示策略,默认值true,可选为:true(显示) | false(隐藏)
    // text: chartData.total + '人', //主标题文本,'\n'指定换行
    text: '人', //主标题文本,'\n'指定换行
    x: 'center', //水平安放位置,默认为'left',可选为:'center' | 'left' | 'right' | {number}(x坐标,单位px)
    y: 'center', //垂直安放位置,默认为top,可选为:'top' | 'bottom' | 'center' | {number}(y坐标,单位px)
    textAlign: null, //水平对齐方式,默认根据x设置自动调整,可选为: left' | 'right' | 'center
    padding: 5, //标题内边距,单位px,默认各方向内边距为5,接受数组分别设定上右下左边距
    // itemGap: 10, //主副标题纵向间隔,单位px,默认为10
    textStyle: {
      //主标题文本样式{"fontSize": 18,"fontWeight": "bolder","color": "#333"}
      fontFamily: 'PingFangSC-Medium, Verdana, sans...',
      fontSize: 14,
      fontStyle: 'normal',
      color: '#333333',
      fontWeight: '600'
    },
    zlevel: 0, //一级层叠控制。默认0,每一个不同的zlevel将产生一个独立的canvas,相同zlevel的组件或图标将在同一个canvas上渲染。zlevel越高越靠顶层,canvas对象增多会消耗更多的内存和性能,并不建议设置过多的zlevel,大部分情况可以通过二级层叠控制z实现层叠控制。
    z: 6 //二级层叠控制,默认6,同一个canvas(相同zlevel)上z越高约靠顶层。
  },
  color: ['#35C376', '#655FED', '#F24724', '#3582EE', '#FF9D0A'],
  tooltip: {
    trigger: 'item',
    formatter: function (params) {
      let txt = params.data.name + ':' + params.data.value
      let list = txt.match(new RegExp(`.{1,6}`, 'g'))
      var html = list.join('\n')
      
      return html
    }
  },

  label: {
    show: true,
    formatter: '{b}\n{c}',
    align: 'right',
    edgeDistance: '10%' // 可以调整文字与饼图边缘的距离
  },
  series: [
    {
      type: 'pie',
      radius: ['40%', '70%'],
      minAngle: 10,
      labelLine: {
        //设置提示线的长度
        normal: {
          length: 10, //第一条线
          length2: 15 //第二条线
        }
      },
      emphasis: {
        label: {
          show: true,
          fontSize: 14
        }
      },
      data: []
    }
  ]
}

export default {
  pieOptions
}