From dd66a08113949a12f5b1587656ab166e59df758c Mon Sep 17 00:00:00 2001 From: panyuyi Date: Wed, 12 Mar 2025 16:41:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E6=9E=81=E5=9D=90?= =?UTF-8?q?=E6=A0=87=E5=9B=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/echartsUtils.js | 83 +++++++++++++++++++ .../statisticsAnalysis/index.vue | 52 ++++++++++-- 2 files changed, 128 insertions(+), 7 deletions(-) diff --git a/src/utils/echartsUtils.js b/src/utils/echartsUtils.js index 006d9d9..2a76e51 100644 --- a/src/utils/echartsUtils.js +++ b/src/utils/echartsUtils.js @@ -167,3 +167,86 @@ export const initCommonPieRingOptions = ({ series: series, }; }; +// 极坐标 +export const initCommonAngleAxisOptions = ({ + data = {}, + colors = ["#36b29e", "#29CCCC", "#0099df", "#81b84a"], + seriesOptions = {}, +}) => { + const { title, yaxis } = data; + let radiusAxisData = []; + let seriesData = []; + let maxVal = 0; + if (yaxis && yaxis.length) { + let newSeries = yaxis.flatMap((v) => v.series); + newSeries.forEach((v, i) => { + radiusAxisData.push(v.name); + seriesData.push({ + value: Number(v.sum ?? null), + itemStyle: { + color: colors[i], + }, + }); + }); + // 设置这个极坐标的最大值,防止占满 + maxVal = Math.max(...newSeries.map((v) => Number(v.sum ?? null))) * 1.25; + } + return { + color: colors, + title: [ + { + show: false, + text: title || "", + }, + ], + polar: { + radius: ["50%", "80%"], + }, + angleAxis: { + max: maxVal, + startAngle: 90, + axisLine: { + show: false, + }, + axisTick: { + show: false, + }, + axisLabel: { + show: false, + }, + splitLine: { + show: false, + }, + }, + radiusAxis: { + show: true, + zlevel: 10, + type: "category", + data: radiusAxisData, + axisLabel: { + interval: 0, // 强制显示所有标签 + }, + axisTick: { + show: false, + }, + axisLine: { + show: false, + }, + splitLine: { + show: false, + }, + }, + tooltip: {}, + series: { + type: "bar", + data: seriesData, + coordinateSystem: "polar", + label: { + show: false, + position: "middle", + formatter: "{b}: {c}", + }, + ...seriesOptions, + }, + }; +}; diff --git a/src/views/dike/runManage/patrolMaintenance/statisticsAnalysis/index.vue b/src/views/dike/runManage/patrolMaintenance/statisticsAnalysis/index.vue index 6b83960..9ae03f1 100644 --- a/src/views/dike/runManage/patrolMaintenance/statisticsAnalysis/index.vue +++ b/src/views/dike/runManage/patrolMaintenance/statisticsAnalysis/index.vue @@ -141,6 +141,7 @@ import { getV2PatrolStatisticChart, getRunProjectList } from "@/api/dike"; import { initCommonBarLineOptions, initCommonPieRingOptions, + initCommonAngleAxisOptions, } from "@/utils/echartsUtils"; export default { @@ -579,13 +580,50 @@ export default { this.yhCompareRefPieInstance = echarts.init( this.$refs.yhCompareRefPie ); - this.yhCompareRefPieInstance.setOption( - initCommonPieRingOptions({ - data: res.data || {}, - colors: ["#0099DF", "#81B84A"], - seriesOptions: {}, - }) - ); + let options = initCommonAngleAxisOptions({ + data: res.data || {}, + colors: [ + { + type: "linear", + x: 0, + y: 0, + x2: 0, + y2: 1, + colorStops: [ + { + offset: 0, + color: "rgba(54, 163, 217, 1)", // 0% 处的颜色 + }, + { + offset: 1, + color: "rgba(54, 163, 217, 0.1)", // 100% 处的颜色 + }, + ], + global: false, // 缺省为 false + }, + { + type: "linear", + x: 0, + y: 0, + x2: 0, + y2: 1, + colorStops: [ + { + offset: 0, + color: "rgba(129, 184, 74, 1)", // 0% 处的颜色 + }, + { + offset: 1, + color: "rgba(129, 184, 74, 0.1)", // 100% 处的颜色 + }, + ], + global: false, // 缺省为 false + }, + ], + seriesOptions: {}, + }); + console.log("options >>>>> ", options); + this.yhCompareRefPieInstance.setOption(options); }); } });