From 040814c3d674ddf7b06470f42832581577c4f378 Mon Sep 17 00:00:00 2001 From: wangxiaoshuang <825034831@qq.com> Date: Tue, 30 Dec 2025 10:24:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=8A=A5=E8=A1=A8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trial-summary/report-forms/index.vue | 69 ++++++++++++++----- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/src/views/trials/trials-panel/trial-summary/report-forms/index.vue b/src/views/trials/trials-panel/trial-summary/report-forms/index.vue index b1958ae8..44318f2f 100644 --- a/src/views/trials/trials-panel/trial-summary/report-forms/index.vue +++ b/src/views/trials/trials-panel/trial-summary/report-forms/index.vue @@ -33,7 +33,7 @@ import BaseContainer from '@/components/BaseContainer' let echarts = require('echarts/lib/echarts'); -// require('echarts/lib/chart/line'); +require('echarts/lib/component/markLine'); require('echarts/lib/chart/funnel'); require('echarts/lib/chart/bar'); // 按需引入组件 @@ -158,7 +158,8 @@ export default { } }, legend: { - data: obj.legendData + data: obj.legendData, + bottom: 0 }, series: [ { @@ -262,7 +263,9 @@ export default { type: 'shadow' } }, - legend: {}, + legend: { + bottom: 0 + }, xAxis: [ { type: 'category', @@ -306,16 +309,17 @@ export default { let obj2 = { xAxisData: [], seriesData: [], + medianValue: 0, unit: this.$t("trials:reportForms:cjart:unit:DaysDiff"), titleText: this.$t("trials:reportForms:cjart:title:dataDistribution"), } if (OtherInfo.PDList && OtherInfo.PDList.length > 0) { OtherInfo.PDList.forEach(item => { - obj.xAxisData.push(item.SubjectCode) - obj.seriesData.push(item.DaysDiff) + obj2.xAxisData.push(item.SubjectCode) + obj2.seriesData.push(item.DaysDiff) }) } - + obj2.medianValue = this.calculateMedian(obj2.seriesData) this.initChart_bottom(obj) this.initChart_bottom_right(obj2) } @@ -373,29 +377,56 @@ export default { xAxis: { type: 'category', data: obj.xAxisData + // data: ['aaa', 'bbb', 'ccc'] }, yAxis: { name: obj.unit, type: 'value' }, - series: [ - { - markLine: { - data: [ - { - type: 'average', name: this.$t("trials:reportForms:cjart:data:average") - } - ] + series: { + markLine: { + // symbol: ['none', 'none'], // 隐藏标记线两端的箭头 + label: { + show: true, + position: 'end', // 将标签显示在线的起点 + formatter: `${this.$t('trials:reportForms:cjart:data:median')}: {c}` // 使用 {c} 自动显示 yAxis 的值 }, - data: obj.seriesData, - type: 'bar', - barWidth: 20, - } - ] + data: [ + { + name: this.$t('trials:reportForms:cjart:data:median'), + // yAxis 的值设置为我们计算出的中位数 + yAxis: obj.medianValue, + lineStyle: { + type: 'dashed', // 设置为虚线 + color: this.color[7] + } + } + ] + }, + data: obj.seriesData, + // data: [1, 2, 3], + type: 'bar', + barWidth: 20, + } + }; // 4. 使用配置项渲染图表 this.chart_bottom_right.setOption(option); }, + calculateMedian(numbers) { + // 1. 创建副本并排序 + const sorted = [...numbers].sort((a, b) => a - b); + const middle = Math.floor(sorted.length / 2); + + // 2. 判断数组长度是奇数还是偶数 + if (sorted.length % 2 === 0) { + // 偶数长度:取中间两个数的平均值 + return (sorted[middle - 1] + sorted[middle]) / 2; + } else { + // 奇数长度:直接取中间的数 + return sorted[middle]; + } + } } }