echart 格式化label标签,formatter使用范例

君子笑而不语 / 2024-10-10 / 原文

 

series: [{
    name: '数量',
    data: result.data.map(o => o.count),
    type: 'bar',
    label:{
      show: true,
      normal: {
        show: true,
        position: 'right',
      },
    },

    showBackground: false,
    backgroundStyle: {
        color: 'rgba(220, 220, 220, 0.8)'
    }
},
  {
    name: '占比',
    data: result.data.map(o => o.rate),
    type: 'bar',
    label:{
      show: true,
      borderRadius: 10,
      normal: {
        formatter: function (params) {
          return params.data * 100 + '%';
        },
        show: true,
        position: 'right',
      },
    },
    showBackground: false,
    backgroundStyle: {
      color: 'rgba(220, 220, 220, 0.8)'
    }
  }]