官網文檔 {d}表示百分比 https://echarts.apache.org/zh/option.html#series-funnel.label.formatter
但是在數據顯示時這個{d}並不是正確對應我數據值的百分比,大部分示例都是直接用{c}%表示
initChartOne() { var myChart = echarts.init(document.querySelector(".line-chart7")); var textColorList = ["#F7DA19", "#00A0FE", "#00D4FF", "#0BFF72"]; var option = { tooltip: { trigger: "item", formatter: "{b} : {c}", }, color: textColorList, series: [ { name: "Funnel", type: "funnel", left: "10%", top: 14, bottom: 30, width: "40%", minSize: "20%", maxSize: "100%", sort: "descending", gap: 2, label: { show: true, formatter: function (params) { //自定義顯示樣式 let rese = "{b|" + params.data.name + "} : {c|" + params.data.value + "}\n{d|" + params.data.valueFat + "%}"; return rese; }, color: "#fff", padding: [0, 100, 20, 0], rich: { b: { fontSize: 16, color: "#fff", }, c: { fontSize: 16, }, d: { fontSize: 18, fontWeight: "bold", lineHeight: 20, }, }, }, labelLine: { length: 40, lineStyle: { width: 1, type: "solid", }, }, itemStyle: { borderColor: "transparent", }, data: [ { //數據值 value: this.callDatas.calledNum === undefined ? "0" : this.callDatas.calledNum, name: "總數", //利用總數計算百分比(去掉小數) valueFat: (this.callDatas.calledNum === 0 ? 0 : (this.callDatas.calledNum / this.callDatas.calledNum) * 100 ).toFixed(0), }, { value: this.callDatas.callConnectedNum === undefined ? "0" : this.callDatas.callConnectedNum, name: "接聽數", valueFat: (this.callDatas.calledNum === 0 ? 0 : (this.callDatas.callConnectedNum / this.callDatas.calledNum) * 100 ).toFixed(0), }, { value: this.callDatas.dissuadeCompletedCount === undefined ? "0" : this.callDatas.dissuadeCompletedCount, name: "完成數", valueFat: (this.callDatas.calledNum === 0 ? 0 : (this.callDatas.dissuadeCompletedCount / this.callDatas.calledNum) * 100 ).toFixed(0), }, { value: this.callDatas.dissuadeCompletedCount === undefined ? "0" : this.callDatas.dissuadeCompletedCount, name: "成功數", valueFat: (this.callDatas.calledNum === 0 ? 0 : (this.callDatas.dissuadeCompletedCount / this.callDatas.calledNum) * 100 ).toFixed(0), }, ], }, ], }; myChart.setOption(option); window.addEventListener("resize", function () { myChart.resize(); }); },