From d31a24ca22ffc8638ca8711eb3ee1cf5bbdecf73 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期一, 03 三月 2025 16:36:55 +0800 Subject: [PATCH] 修复新增巡查子任务时,巡查人员信息没有正确录入的问题 --- src/utils/echart-util.js | 123 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 123 insertions(+), 0 deletions(-) diff --git a/src/utils/echart-util.js b/src/utils/echart-util.js new file mode 100644 index 0000000..0934d69 --- /dev/null +++ b/src/utils/echart-util.js @@ -0,0 +1,123 @@ +// 閫掑綊鐨勮幏鍙杘bj涓殑prop灞炴�� 瑙e喅鏈夋椂闇�瑕佸彇val.obj.prop鐨勬儏鍐� +function getPropValueLoop(obj, prop) { + if (typeof prop !== 'string') { + return obj; + } + const props = prop.split('.'); + let result = obj; + props.forEach((item) => { + result = result[item]; + }); + return result; +} +function getCount(array, element) { + let count = 0; + array.forEach((e) => { + if (e == element) { + count++; + } + }); + return count; +} +export default { + /** 灏哻hart鍥捐〃杞寲涓哄浘鐗噓rl + * @param chart锛� chart鍥捐〃鐨勫疄渚� + * */ + chartToImageUrl(chart) { + const dataURL = chart.getDataURL({ + pixelRatio: 5, // 鎻愰珮鍥剧墖璐ㄩ噺 + backgroundColor: '#FFFFFF', // 璁剧疆鑳屾櫙棰滆壊 + excludeComponents: ['toolbox'], // 鎺掗櫎宸ュ叿绠辩粍浠� + type: 'png' // 杈撳嚭鍥剧墖绫诲瀷涓篜NG + }); + return dataURL; + }, + // 灞曠ず data 鏁扮粍涓璞$殑 prop 灞炴�х殑楗煎浘, title 鏄ゼ鍥剧殑鏍囬 + getPieChartByDataAndProp(data, prop, label) { + let chartData = []; + function hasThisName(name) { + for (let index = 0; index < chartData.length; index++) { + const element = chartData[index]; + if (element.name === name) { + return true; + } + } + return false; + } + + data.map((item) => { + const name = getPropValueLoop(item, prop); + if (hasThisName(name)) { + chartData.map((item) => { + if (item.name === name) { + item.value++; + } + }); + } else { + chartData.push({ + name: name, + value: 1 + }); + } + }); + + return { + title: { + text: label, + left: 'center' + }, + tooltip: { + trigger: 'item' + }, + legend: { + orient: 'vertical', + left: 'left' + }, + series: [ + { + type: 'pie', + radius: '50%', + data: chartData, + emphasis: { + itemStyle: { + shadowBlur: 10, + shadowOffsetX: 0, + shadowColor: 'rgba(0, 0, 0, 0.5)' + } + } + } + ] + }; + }, + // 灞曠ず data 鏁扮粍涓璞$殑 prop 灞炴�х殑鐩存柟鍥�, title 鏄洿鏂瑰浘鐨勬爣棰� + getBarChartByDataAndProp(data, prop, title) { + let series = data.map((item) => getPropValueLoop(item, prop)); + const option = { + title: { + text: title //璁剧疆鏍囬 + }, + xAxis: { + type: 'category', + data: Array.from(new Set(series)), + axisLabel: { + rotate: 45, // 鏃嬭浆鏍囩锛岄伩鍏嶉噸鍙� + // 鎴栬�� + interval: 0 // 鏄剧ず鎵�鏈夋爣绛撅紝鍙兘瀵艰嚧閲嶅彔锛屾牴鎹渶姹傝皟鏁� + } + }, + yAxis: { + type: 'value' + }, + series: [ + { + data: Array.from(new Set(series)).map((item) => + getCount(series, item) + ), + type: 'bar', + smooth: true + } + ] + }; + return option; + } +}; -- Gitblit v1.9.3