export default function tjOption(obj) { let title = "总计"; let color = ["#73a0fa", "#52c1f5"]; let echartData = [ { name: "灌溉用水", value: parseFloat(obj?.shgs?.toFixed(2)) }, { name: "水厂取水", value: parseFloat(obj?.stgs?.toFixed(2)), }, ]; 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(2).toString() + "%"; } return{ color: color, title: [ { text: "{name|" + title + "}\n{val|" + formatNumber(total) + "}{unit|" + "万m³" + "}", top: "center", left: "center", textStyle: { rich: { name: { fontSize: 16, fontWeight: "bold", color: "#007afd", padding: [10, 0], }, val: { fontSize: 28, fontWeight: "bold", padding: [0, 5], color: "#333333", }, unit:{ fontSize: 12, color:"#000" } }, }, }, ], series: [ { type: "pie", radius: ["40%", "60%"], center: ["50%", "50%"], data: echartData, hoverAnimation: false, itemStyle: { normal: { // borderColor: bgColor, borderWidth: 2, }, }, labelLine: { normal: { length: 60, // length2: 120, lineStyle: { color: "#e6e6e6", }, }, }, label: { normal: { formatter: (params) => { return ( "{name|" + params.name + ':'+"}{value|" + percentFormat(params.value)+ "}\n{total|" + formatNumber(params.value) + '' +'万m³'+ "}" ); }, // padding: [0, -100, 25, -100], rich: { name: { fontSize: 16, padding: [0, 5, 10, 4], color: "#666666", }, value: { fontSize: 14, color: "#333333", padding: [0, 0, 10, 4], }, total: { fontSize: 14, color: "#333333", align:"left", lineHeight:23 } }, }, }, }, ], }; }