const color = ['#ffdc2b', '#4d8cfd', '#45e6de']; const datas = [ { name: '服务业企业', value: 25, }, { name: '批发零售企业', value: 75, }, { name: '住宿餐饮企业', value: 75, }, ]; let sum = 0; for (var i of datas) { sum += i.value; } const title = { name: '企业总数', value: sum, unit: '家', }; const rich = { name: { color: '#DEDEDE', fontSize: 16, align: 'left', padding: [0, 10, 20, 0], }, name1: { color: '#DEDEDE', fontSize: 16, align: 'left', padding: [0, 0, 0, 10], }, value: { color: '#ccc', fontSize: 14, align: 'left', }, title: { color: '#fff', fontSize: 17, }, titleUnit: { color: '#fff', fontSize: 16, padding: [15, 0, 0, 0], }, titleValue: { color: '#fff', fontSize: 40, fontWeight: 600, padding: [15, 5, 5, 5], }, }; let option = { color, backgroundColor: '#000E1A', legend: { orient: 'vertical', icon: 'circle', x: '55%', y: 'center', itemWidth: 12, itemHeight: 12, itemGap: 20, width: '263', align: 'left', textStyle: { color: '#D7E5FF', rich, }, formatter: function (name) { debugger; let res = datas.filter(v => v.name === name) let str = '' str = '{name1|' + res[0].name + '}{name1|' + res[0].value + '家}' return str }, }, series: [ { type: 'pie', center: ['30%', '50%'], radius: ['40%', '50%'], data: datas, startAngle: 180, label: { show: false, }, }, { type: 'pie', center: ['30%', '50%'], radius: ['40%', '50%'], data: datas, startAngle: 180, label: { show: true, position: 'center', formatter: () => `{title|${title.name}}\n{titleValue|${title.value}}{titleUnit|${title.unit}}`, rich, }, }, ], };