option = { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, legend: {}, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: { type: 'value' }, yAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, series: [ { name: 'Direct', type: 'bar', stack: 'total', label: { show: true }, emphasis: { focus: 'series' }, data: [320, 302, 301, 334, 390, 330, 320] }, { name: 'Mail Ad', type: 'bar', stack: 'total', label: { show: true }, emphasis: { focus: 'series' }, data: [120, 132, 101, 134, 90, 230, 210] }, { name:"总数", type: 'bar', barWidth:"0%", stack:"total", label:{ show:true, color: 'rgb(250, 200, 88)', formatter:function(params){ console.log(params) return '2' }, position:"right" }, data:[0,0,0,0,0,0,0] } ] }; const returnRate = function (num, total, len = 2) { const numeratorBackup = Number(num) const denominatorBackup = Number(total) if (denominatorBackup === 0 || numeratorBackup === 0) { return 0 } else { const result = numeratorBackup / denominatorBackup let val = 0 const divisor = result.toString().indexOf('.') !== -1 ? result.toString().split('.')[1] : result if (numeratorBackup % denominatorBackup === 0 || divisor.length <= len) { val = ((numeratorBackup / denominatorBackup) * 100).toFixed(len) } else { val = ((numeratorBackup / denominatorBackup) * 100).toFixed(len) } return Number(val) } } var series = option.series function getSum (params) { let dataValue = 0 for (let i = 0; i < series.length; i++) { dataValue += series[i].data[params.dataIndex] } return returnRate(dataValue,600) + '%' } series[series.length - 1].label.formatter = getSum