对接报表
This commit is contained in:
		
							
								
								
									
										157
									
								
								src/views/report/completionStatusIntrBM/components/baseChart.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										157
									
								
								src/views/report/completionStatusIntrBM/components/baseChart.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,157 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div
 | 
			
		||||
    :id="chartId"
 | 
			
		||||
    :style="{ width: '100%', height: chartHeight + 'px' }"
 | 
			
		||||
  ></div>
 | 
			
		||||
</template>
 | 
			
		||||
<script>
 | 
			
		||||
import * as echarts from "echarts";
 | 
			
		||||
import { debounce } from "@/utils/debounce";
 | 
			
		||||
export default {
 | 
			
		||||
  name: "BaseChart",
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      myChart: "",
 | 
			
		||||
      option: {
 | 
			
		||||
        color: [],
 | 
			
		||||
        // color: ["#8EF0AB", "#63BDFF", "#288AFF"],
 | 
			
		||||
        grid: {
 | 
			
		||||
          left: 70,
 | 
			
		||||
          right: 10,
 | 
			
		||||
          bottom: 30,
 | 
			
		||||
          top: 30,
 | 
			
		||||
        },
 | 
			
		||||
        tooltip: {
 | 
			
		||||
          trigger: "axis",
 | 
			
		||||
          axisPointer: {
 | 
			
		||||
            // type: "cross",
 | 
			
		||||
            crossStyle: {
 | 
			
		||||
              color: "rgba(237,237,237,0.5)",
 | 
			
		||||
            },
 | 
			
		||||
          },
 | 
			
		||||
          formatter: function (params) {
 | 
			
		||||
            var res = `<span style='color:rgba(0,0,0,0.8)'>${params[0].axisValueLabel}</span>`;
 | 
			
		||||
            for (var i = 0, l = params.length; i < l; i++) {
 | 
			
		||||
              res +=
 | 
			
		||||
                "<br/>" +
 | 
			
		||||
                `${
 | 
			
		||||
                  params[i].seriesType === "line"
 | 
			
		||||
                    ? '<img width="10" height="10" style="margin-right:4px;" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTg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MxMDQ1LDggMTIuMzYwODE5Nyw4IEwxMS4wMTI5NjY3LDguMDAwNzYxMzQgQzEwLjU2ODY1OTIsOS43MjU2MDIyNCA5LjAwMjc0NTUxLDExIDcuMTM5MTgwMjYsMTEgQzUuMjc1NjE1MDEsMTEgMy43MDk3MDEzMSw5LjcyNTYwMjI0IDMuMjY1MzkzNzgsOC4wMDA3NjEzNCBMMS42MzkxODAyNiw4IEMxLjA4Njg5NTUxLDggMC42MzkxODAyNTgsNy41NTIyODQ3NSAwLjYzOTE4MDI1OCw3IEMwLjYzOTE4MDI1OCw2LjQ0NzcxNTI1IDEuMDg2ODk1NTEsNiAxLjYzOTE4MDI2LDYgTDMuMjY1MTM1MDksNi4wMDAyNDM0NyBDMy43MDkwOTMyLDQuMjc0ODkyNzIgNS4yNzUyNTMxNSwzIDcuMTM5MTgwMjYsMyBaIiBpZD0i5b2i54q257uT5ZCIIiBmaWxsPSIjRkZDRTZBIiBmaWxsLXJ1bGU9Im5vbnplcm8iPjwvcGF0aD4KICAgICAgICAgICAgICAgIDwvZz4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+" />'
 | 
			
		||||
                    : `<span style="display:inline-block;margin-right:4px;border-radius:2px;width:10px;height:10px;background-color:${params[i].color}"></span>`
 | 
			
		||||
                }` +
 | 
			
		||||
                `<span style='display:inline-block;width:180px;color:rgba(0,0,0,0.8);font-size:14px;'>${params[i].seriesName}</span>` +
 | 
			
		||||
                `<span style='color:rgba(0,0,0,0.48);font-size:14px;'>${
 | 
			
		||||
                  params[i].name === "%"
 | 
			
		||||
                    ? (params[i].value ? params[i].value.toFixed(2) : "0.00") +
 | 
			
		||||
                      params[i].name
 | 
			
		||||
                    : String(params[i].value).replace(
 | 
			
		||||
                        /\B(?=(\d{3})+(?!\d))/g,
 | 
			
		||||
                        ","
 | 
			
		||||
                      )
 | 
			
		||||
                }</span>`;
 | 
			
		||||
            }
 | 
			
		||||
            return res;
 | 
			
		||||
          },
 | 
			
		||||
        },
 | 
			
		||||
        xAxis: {
 | 
			
		||||
          type: "category",
 | 
			
		||||
          data: [],
 | 
			
		||||
          axisTick: {
 | 
			
		||||
            show: false,
 | 
			
		||||
          },
 | 
			
		||||
          axisPointer: {
 | 
			
		||||
            type: "shadow",
 | 
			
		||||
          },
 | 
			
		||||
        },
 | 
			
		||||
        yAxis: {
 | 
			
		||||
          type: "value",
 | 
			
		||||
          name: "",
 | 
			
		||||
          nameTextStyle: {
 | 
			
		||||
            fontSize: 12,
 | 
			
		||||
            align: "right",
 | 
			
		||||
          },
 | 
			
		||||
          axisLabel: {},
 | 
			
		||||
        },
 | 
			
		||||
        series: [],
 | 
			
		||||
      },
 | 
			
		||||
    };
 | 
			
		||||
  },
 | 
			
		||||
  props: {
 | 
			
		||||
    chartHeight: {
 | 
			
		||||
      type: Number,
 | 
			
		||||
      default: 300,
 | 
			
		||||
    },
 | 
			
		||||
    legendList: {
 | 
			
		||||
      type: Array,
 | 
			
		||||
      default: () => [],
 | 
			
		||||
    },
 | 
			
		||||
    chartMsg: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
    chartId: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: "bmChart",
 | 
			
		||||
    },
 | 
			
		||||
    chartNum: {
 | 
			
		||||
      type: Number,
 | 
			
		||||
      default: 1,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  watch: {
 | 
			
		||||
    chartHeight: {
 | 
			
		||||
      handler(newVal) {
 | 
			
		||||
        this.chartHeight = newVal;
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
    chartNum(val) {
 | 
			
		||||
      this.canvasReset();
 | 
			
		||||
    },
 | 
			
		||||
    chartMsg: {
 | 
			
		||||
      handler(newVal) {
 | 
			
		||||
        this.canvasReset();
 | 
			
		||||
      },
 | 
			
		||||
      deep: true,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  mounted() {
 | 
			
		||||
    this.canvasReset();
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    canvasReset() {
 | 
			
		||||
      debounce(() => {
 | 
			
		||||
        this.getMes();
 | 
			
		||||
      }, 500)();
 | 
			
		||||
    },
 | 
			
		||||
    getMes() {
 | 
			
		||||
      if (this.myChart) {
 | 
			
		||||
        this.myChart.dispose();
 | 
			
		||||
      }
 | 
			
		||||
      var chartDom = document.getElementById(this.chartId);
 | 
			
		||||
      this.myChart = echarts.init(chartDom);
 | 
			
		||||
      this.option.color = this.chartMsg.color;
 | 
			
		||||
      this.option.xAxis.data = this.chartMsg.xData;
 | 
			
		||||
      this.option.yAxis.name = this.chartMsg.yName;
 | 
			
		||||
      if (
 | 
			
		||||
        this.chartMsg.series.length > 0 &&
 | 
			
		||||
        this.chartMsg.series[0].data[0].name === "%"
 | 
			
		||||
      ) {
 | 
			
		||||
        this.option.yAxis.axisLabel = {
 | 
			
		||||
          formatter: function (value) {
 | 
			
		||||
            return value + ".00%";
 | 
			
		||||
          },
 | 
			
		||||
        };
 | 
			
		||||
      } else {
 | 
			
		||||
        this.option.yAxis.axisLabel = {
 | 
			
		||||
          formatter: function (value) {
 | 
			
		||||
            return value;
 | 
			
		||||
          },
 | 
			
		||||
        };
 | 
			
		||||
      }
 | 
			
		||||
      // this.option.yAxis.axisLabel = this.chartMsg.yAxisLabel;
 | 
			
		||||
      this.option.series = this.chartMsg.series;
 | 
			
		||||
      this.myChart.setOption(this.option);
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
};
 | 
			
		||||
</script>
 | 
			
		||||
		Reference in New Issue
	
	Block a user