Przeglądaj źródła

兼容相关性图表

jwyu 2 lat temu
rodzic
commit
d304bc45af
2 zmienionych plików z 112 dodań i 4 usunięć
  1. 9 0
      src/request/api.ts
  2. 103 4
      src/views/chartShow/index.vue

+ 9 - 0
src/request/api.ts

@@ -34,6 +34,15 @@ export const ChartApi = {
 	 */
 	refreshCommordityChart: (params:IRefreshParams) => {
 		return get('/chart/future_good/refresh',params)
+	},
+
+	/**
+	 * 商品价格图表刷新
+	 * @param params UniqueCode
+	 * @returns 
+	 */
+	refreshRelevanceChart: (params:IRefreshParams) => {
+		return get('/chart/correlation/refresh',params)
 	}
 }
 

+ 103 - 4
src/views/chartShow/index.vue

@@ -158,8 +158,10 @@ export default defineComponent({
 
         if(Data.ChartInfo.Source === 1) {
           state.chartInfo.ChartType === 7 ? initBarData(Data) : setOptions();
-        }else {
+        }else if(Data.ChartInfo.Source === 2) {
           initCommodityData(Data)
+        }else if(Data.ChartInfo.Source === 3){
+          initRelevanceChartData(Data)
         }
         
         dealSourceHandle();
@@ -172,6 +174,98 @@ export default defineComponent({
 
     };
 
+    /* 相关性图表 */
+    const initRelevanceChartData=(data)=>{
+      // 处理X轴
+      let xAxis={
+        categories: data.XEdbIdValue,
+        tickWidth: 1,
+        title: {
+          text:  `期数(${data.CorrelationChartInfo.LeadUnit})`,
+          align: 'high',
+          rotation: 0,
+          x: 0,
+          y:10,
+          offset: 20,
+        },
+        tickInterval: 1,
+        offset:-85,
+        tickmarkPlacement:'on'
+      }
+
+      // 处理Y轴
+      let yAxis={
+        ...basicYAxis,
+        title: {
+          text: '相关性系数',
+          textCh: '相关性系数',
+          textEn: 'Correlation coefficient',
+          align: 'high',
+          rotation: 0,
+          y: -15,
+          offset: 0,
+        },
+        labels: {
+          formatter: function (ctx) {
+            let val = ctx.value;
+            return val;
+          },
+          align: 'center',
+        },
+        min: -1,
+        max: 1,
+        opposite: false,
+        tickWidth: 1,
+        tickInterval:0.2,
+      }
+
+      //处理series
+      let seriesData=[]
+      data.YDataList.forEach(item=>{
+        let serie_item = {
+          data: item.Value,
+          type: 'spline',
+          yAxis: 0,
+          name: data.ChartInfo.ChartName,
+          nameCh: data.ChartInfo.ChartName,
+          nameEn: data.ChartInfo.ChartNameEn,
+          color: item.Color,
+          chartType: 'linear',
+          lineWidth: 3,
+          marker: {
+            enabled: false
+          }
+        };
+        seriesData.push(serie_item)
+      })
+
+      let tooltip = {
+        formatter: function() {
+          let str = `<p>相关性系数:${this.y}</p>`
+          return str
+        },
+        formatterCh: function() {
+          let str = `<p>相关性系数:${this.y}</p>`
+          return str
+        },
+        formatterEn: function() {
+          let str = `<p>Correlation coefficient:${this.y}</p>`
+          return str
+        }
+      }
+
+      state.options = {
+        isRelevanceChart:true,
+        title: {
+          text:''
+        },
+        series: seriesData,
+        yAxis: [yAxis] ,
+        xAxis:xAxis,
+        tooltip
+      }
+    }
+
     /* 获取图表详情后赋值柱状图数据 */
     const initBarData = (data: { XEdbIdValue: number[]; YDataList: any; EdbInfoList: any; ChartInfo: any; }) => {
       const { XEdbIdValue,YDataList,EdbInfoList,ChartInfo } = data;
@@ -1175,9 +1269,14 @@ export default defineComponent({
 
     const refreshChart = _.debounce(async () => {
       loading.value = true;
-      let { Ret } = state.chartInfo.Source === 1 
-        ? await ChartApi.refreshChart({UniqueCode: state.chartInfo.UniqueCode})
-        : await ChartApi.refreshCommordityChart({UniqueCode: state.chartInfo.UniqueCode});
+      let Ret=null
+      if(state.chartInfo.Source === 1){
+        Ret=await ChartApi.refreshChart({UniqueCode: state.chartInfo.UniqueCode})
+      }else if(state.chartInfo.Source === 2){
+        Ret=await ChartApi.refreshCommordityChart({UniqueCode: state.chartInfo.UniqueCode});
+      }else if(state.chartInfo.Source === 3){
+        Ret=await ChartApi.refreshRelevanceChart({UniqueCode: state.chartInfo.UniqueCode});
+      }
         
       Ret === 200 && getChartInfo('refresh');
     },400)