Jelajahi Sumber

价格增加均线

wukai 1 bulan lalu
induk
melakukan
e3a383fa53
2 mengubah file dengan 86 tambahan dan 4 penghapusan
  1. 42 2
      src/views/lean/qh/calc.vue
  2. 44 2
      src/views/lean/xh/calc.vue

+ 42 - 2
src/views/lean/qh/calc.vue

@@ -448,6 +448,46 @@ function initCharts() {
         const yAxisMin = Math.floor(minY - range * 0.1);
         const yAxisMax = Math.ceil(maxY + range * 0.1);
 
+        // 计算所有数据点的平均值
+        let totalPrice = 0;
+        let totalCount = 0;
+        
+        chartList.value[index].series.forEach(series => {
+          series.data.forEach(item => {
+            const price = item[1];
+            totalPrice += price;
+            totalCount++;
+          });
+        });
+        
+        const averagePrice = totalCount > 0 ? totalPrice / totalCount : 0;
+
+        // 创建平均线数据
+        const averageLine = {
+          name: '平均价',
+          type: 'line',
+          markLine: {
+            symbol: 'none',
+            label: {
+              position: 'middle',
+              formatter: '平均价: ' + averagePrice.toFixed(2) + ' 元'
+            },
+            data: [
+              { 
+                yAxis: averagePrice,
+                lineStyle: {
+                  color: '#FF0000',
+                  width: 2,
+                  type: 'dashed'
+                }
+              }
+            ]
+          }
+        };
+
+        // 合并原系列数据和平均线
+        const allSeries = [...chartList.value[index].series, averageLine];
+
         // 配置图表选项
         const option = {
           title: {
@@ -473,7 +513,7 @@ function initCharts() {
             }
           },
           legend: {
-            data: chartList.value[index].series.map(item => item.name), // 显示品名
+            data: [...chartList.value[index].series.map(item => item.name), '平均价'], // 显示品名和平均价
             top: '10%'
           },
           grid: {
@@ -512,7 +552,7 @@ function initCharts() {
               show: false
             }
           },
-          series: chartList.value[index].series
+          series: allSeries
         };
 
         // 设置图表选项

+ 44 - 2
src/views/lean/xh/calc.vue

@@ -467,6 +467,48 @@ function initCharts() {
         const yAxisMin = minY - 0.5;
         const yAxisMax = maxY + 0.5;
 
+        // 计算所有数据点的平均值
+        let totalPrice = 0;
+        let totalCount = 0;
+        
+        chartList.value[index].series.forEach(series => {
+          series.data.forEach(item => {
+            const price = item[1];
+            if (price !== 0) {
+              totalPrice += price;
+              totalCount++;
+            }
+          });
+        });
+        
+        const averagePrice = totalCount > 0 ? totalPrice / totalCount : 0;
+
+        // 创建平均线数据
+        const averageLine = {
+          name: '平均价',
+          type: 'line',
+          markLine: {
+            symbol: 'none',
+            label: {
+              position: 'middle',
+              formatter: '平均价: ' + averagePrice.toFixed(2) + ' 元'
+            },
+            data: [
+              { 
+                yAxis: averagePrice,
+                lineStyle: {
+                  color: '#FF0000',
+                  width: 2,
+                  type: 'dashed'
+                }
+              }
+            ]
+          }
+        };
+
+        // 合并原系列数据和平均线
+        const allSeries = [...chartList.value[index].series, averageLine];
+
         // 配置图表选项
         const option = {
           title: {
@@ -492,7 +534,7 @@ function initCharts() {
             }
           },
           legend: {
-            data: chartList.value[index].series.map(item => item.name), // 只显示厂家名称
+            data: [...chartList.value[index].series.map(item => item.name), '平均价'], // 只显示厂家名称
             top: '10%'
           },
           grid: {
@@ -531,7 +573,7 @@ function initCharts() {
               show: false
             }
           },
-          series: chartList.value[index].series
+          series: allSeries
         };
 
         // 设置图表选项