const myCharte = echarts.init(document.getElementById('demo'), 'vintage'); datae = [{ name: "今日", value:100 }, { name: "本周", value: 100 }, { name: "本月", value:100 }, ]; arrName = getArrayValue(datae, "name"); arrValue = getArrayValue(datae, "value"); sumValue = eval(arrValue.join('+')); objData = array2obj(datae, "name"); optionData = getData(datae) function getArrayValue(array, key) { var key = key || "value"; var res = []; if (array) { array.forEach(function(t) { res.push(t[key]); }); } return res; } function array2obj(array, key) { var resObj = {}; for (var i = 0; i < array.length; i++) { resObj[array[i][key]] = array[i]; } return resObj; } function getData(data) { var res = { series: [], yAxis: [] }; for (let i = 0; i < data.length; i++) { // console.log([70 - i * 15 + '%', 67 - i * 15 + '%']); res.series.push({ name: '', type: 'pie', clockWise: false, //顺时加载 hoverAnimation: false, //鼠标移入变大 radius: [80 - i * 15 + '%', 70 - i * 15 + '%'], center: ["50%", "55%"], label: { show: false }, itemStyle: { label: { show: false, }, labelLine: { show: false }, borderWidth: 0, }, data: [{ value: datae[i].value, name: datae[i].name }, { value: sumValue - data[i].value, name: '', itemStyle: { color: "rgba(0,0,0,0)", borderWidth: 0 }, tooltip: { show: false }, hoverAnimation: false }] }); res.series.push({ name: '', type: 'pie', silent: true, z: 1, clockWise: false, //顺时加载 hoverAnimation: false, //鼠标移入变大 radius: [80 - i * 15 + '%', 70 - i * 15 + '%'], center: ["50%", "55%"], label: { show: false }, itemStyle: { label: { show: false }, labelLine: { show: false }, borderWidth: 0, }, data: [{ value: 7.5, itemStyle: { color: "rgb(3, 31, 62)", borderWidth: 0 }, tooltip: { show: false }, hoverAnimation: false }, { value: 2.5, name: '', itemStyle: { color: "rgba(0,0,0,0)", borderWidth: 0 }, tooltip: { show: false }, hoverAnimation: false }] }); res.yAxis.push((datae[i].value / sumValue * 100).toFixed(2) + "%"); } return res; } option45 = { legend: { show: true, selectedMode: false, icon: "circle", top: "center", top: '15%', bottom: '53%', left: "50%", data: arrName, width: 40, padding: [0, 16], itemGap: 25, formatter: function(name) { return "{title|" + name + "}{value|" + (objData[name].value) + "} {title|项}" }, textStyle: { rich: { title: { fontSize: 20, lineHeight: 30, color: "#00e4ff" }, value: { fontSize:30, padding:[0,8,0,10], lineHeight: 20, color: "#fcdc00" } } }, }, tooltip: { show: true, trigger: "item", formatter: "{a}{b}:{c}({d}%)", textStyle:{ fontSize:30 } }, color: ['#009944', '#ffa531', '#00ccff', 'rgb(52, 52, 176)'], xAxis: [{ show: false }], series: optionData.series }; myCharte.setOption(option45);