饼图标签示例

描述:当前是关于Echarts图表中的 饼图 示例。
 
            /* CSDN博客网址:https://blog.csdn.net/qq_36604536/article/details/124153574 */

let pieColors = ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de']
let richColor = {}
pieColors.forEach((item, idx) => {
  richColor[`color${idx}`] = { 
    fontSize: 28,
    color: item
  }
})

let chartData = [
  { value: 1048, name: 'Search Engine' },
  { value: 735, name: 'Direct' },
  { value: 580, name: 'Email' },
  { value: 484, name: 'Union Ads' },
  { value: 300, name: 'Video Ads' }
]

option = {
  color: pieColors,
  series: [
    {
      name: 'Access From',
      type: 'pie',
      radius: ['36%', '56%'],
      avoidLabelOverlap: false,
      label: {
        formatter: params => {
          // console.log(params)
          return `{color${params.dataIndex}|${params.name}(${params.value})}`
        },
        rich: richColor
      },
      labelLine: {
        lineStyle: {
          width: 3
        }
      },
      data: chartData
    },
    {
      name: '数据总数',
      type: 'pie',
      radius: ['0%', '0%'],
      itemStyle: { // 防止鼠标悬浮到标签时出现放大的点
        color: 'transparent'
      },
      label: {
        position: 'inside',
        formatter: `{data|{c}}\n{serie|{a}}`,
        rich: {
          data: {
            fontWeight: 'bold',
            fontSize: 64,
            color: `#202020`,
            lineHeight: 68,
            textBorderColor: `transparent`,
            textBorderWidth: 0
          },
          serie: {
            fontSize: 24,
            color: `#acbac6`,
            lineHeight: 28,
            textBorderColor: `transparent`,
            textBorderWidth: 0
          }
        }
      },
      labelLine: {
        show: false
      },
      data: [ // 计算表格数据value总和
        chartData.reduce((prev, cur) => prev + cur.value, 0)
      ]
    }
  ]
};