export default function tjOption(obj) { let title = "优秀"; let color = ["#91cc75", "#5470c6","#ffc542","#ff7474"]; let echartData = [ { name: "优秀", value: obj[1] || 0 }, { name: "良好", value: obj[2] || 0, }, { name: "合格", value: obj[3] || 0, }, { name: "不合格", value: obj[4] || 0, }, ]; let formatNumber = function (num) { let reg = /(?=(\B)(\d{3})+$)/g; return num.toString().replace(reg, ","); }; let total = echartData.reduce((a, b) => { return a + b.value * 1; }, 0); let percentFormat = function (num){ return ((num / total) * 100)?.toFixed(0).toString() + "%"; } let wzgPrecent = percentFormat(echartData[0]?.value) return { color: color, legend: { show: true, orient: 'vertical', right: '80', top: 'center', itemWidth: 17, itemHeight: 15, itemGap:20, textStyle: { fontSize: 14, rich: { a: { color: '#000', width: 30 }, b:{ color: '#000', fontSize: 14, padding: [0, 30, 0, 40] }, } }, formatter: function(name) { let title = '' var target; var index; for (var i = 0, l = echartData.length; i < l; i++) { if (echartData[i].name == name) { target = echartData[i].value; title = echartData[i].label index = i < 6 ? i : 5 } } return `{a| ${name}}{b| ${target}}` } }, title: [ { // text: "{name|" + title + "}\n{val|" + formatNumber(total) + "}{unit|" + "万m³" + "}", text: "{val|" + wzgPrecent + "}\n{name|" + title + "}", top: "center", left: "35%", textStyle: { rich: { name: { fontSize: 14, color: "#a2a2a2", padding: [10, 10], }, val: { fontSize: 28, fontWeight: "bold", padding: [0, -5], color: "#333333", }, }, }, }, ], series: [ { type: "pie", radius: ["40%", "60%"], center: ["40%", "50%"], data: echartData, hoverAnimation: false, itemStyle: { normal: { // borderColor: bgColor, borderWidth: 2, }, }, labelLine: { show:false }, label: { show:false } }, ], }; }