incomeProductOption.js 2.46 KB
const incomeProductOption = {
  color: [
    'rgba(9,71,198,0.8)',
    'rgba(255,178,25,1)',
    'rgba(255,178,25,0.8)',
    'rgba(0,157,255,1)',
    'rgba(0,157,255,0.8)',
    'rgba(0,157,255,0.6)',
    'rgba(0,228,115,1)',
    'rgba(0,228,115,0.8)'
  ],
  title: {
    text: '累计收入\n555555元',
    top: '50%',
    left: '50%',
    textAlign: 'center',
    textStyle: {
      color: '#485465',
      width: '160px',
      lineHeight: 20,
      fontSize: 14
    }
  },
  tooltip: {
    trigger: 'item',
    formatter: params => {
      return `${insertTooltipBr(params.name)} : ${params.value}(${
        params.percent
      }%)`
    },
    position: [10, 10]
  },
  series: [
    {
      name: '毛利',
      type: 'pie',
      minAngle: 5,
      avoidLabelOverlap: true,
      radius: ['40%', '60%'],
      center: ['50%', '60%'],
      label: {
        show: false
        /* align: 'left',
        normal:{
          formatter(v) {
            let text = v.name
            return insertBr(text)
          },
          textStyle : {
            fontSize : 10
          }
        } */
      },
      data: [
        { value: 335, name: '直接访问' },
        { value: 310, name: '邮件营销' },
        { value: 234, name: '联盟广告' },
        { value: 135, name: '视频广告' },
        { value: 1548, name: '搜索引擎' }
      ],
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }
  ]
}
// function insertBr(text) {
//   if (text.length <= 8) {
//     return text
//   } else if (text.length > 8 && text.length <= 16) {
//     return (text = `${text.slice(0, 8)}\n${text.slice(8)}\n`)
//   } else if (text.length > 16 && text.length <= 24) {
//     return (text = `${text.slice(0, 8)}\n${text.slice(8, 16)}\n${text.slice(
//       16
//     )}\n`)
//   } else if (text.length > 24 && text.length <= 30) {
//     return (text = `${text.slice(0, 8)}\n${text.slice(8, 16)}\n${text.slice(
//       16,
//       24
//     )}\n${text.slice(24)}\n`)
//   } else if (text.length > 30) {
//     return (text = `${text.slice(0, 8)}\n${text.slice(8, 16)}\n${text.slice(
//       16,
//       24
//     )}\n${text.slice(24, 30)}\n${text.slice(30)}\n`)
//   }
// }
function insertTooltipBr(text) {
  if (text.length <= 30) {
    return text
  } else if (text.length > 30) {
    text = `${text.slice(0, 30)}</br>${text.slice(30)}`
    return text
  }
}
export default incomeProductOption