| 77ebf04d  梁保满
 
个人版 | 1
2
3
4
5
6
7
8
9
10
11 |   <template>
    <div class="chart" :id="id"></div>
  </template>
  
  <script>
  export default {
    name: "lineChart",
    props: {
      id: String,
      params: Array,
      xAxis: Array,
 | 
| 22095aba  梁保满
 
接口联调 | 12 |       colors: Array,
 | 
| ce278878  梁保满
 
2-2 bugfix | 13
14 |       formatterYAxis: true,
      tooltipFormatter:false
 | 
| 77ebf04d  梁保满
 
个人版 | 15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |     },
    watch: {
      params: {
        handler: function (val) {
          if (val.length) {
            this.initData();
          }
        },
        deep: true,
      },
    },
    data() {
      return {
        chart: null,
      };
    },
 | 
| 079cb4cf  梁保满
 
即时测导出 | 31 |     created() { },
 | 
| 77ebf04d  梁保满
 
个人版 | 32
33
34
35
36
37
38 |     mounted() {
      this.initData();
    },
    methods: {
      setOption() {
        const that = this;
        const options = {
 | 
| 079cb4cf  梁保满
 
即时测导出 | 39 |           color: this.colors || ["#9772ff", "#79cd91", "#72b8ff"],
 | 
| 77ebf04d  梁保满
 
个人版 | 40
41
42
43 |           backgroundColor: "#fff",
          tooltip: {
            trigger: "item",
            confine: true,
 | 
| ce278878  梁保满
 
2-2 bugfix | 44
45 |             formatter(v) {
              let html = `<p>${v.seriesName}</p>`
 | 
| b0cd2598  梁保满
 
fix:测试问题 | 46 |               html += `${v.marker} ${v.name}:${Number(v.value)}${that.tooltipFormatter?'%':''}`
 | 
| ce278878  梁保满
 
2-2 bugfix | 47
48 |               return html
            },
 | 
| 77ebf04d  梁保满
 
个人版 | 49
50
51 |           },
          legend: {
            show: true,
 | 
| 079cb4cf  梁保满
 
即时测导出 | 52
53
54
55 |             top: 0,
            right: 20,
            itemHeight: 15,
            icon: "circle"
 | 
| 77ebf04d  梁保满
 
个人版 | 56
57
58
59
60
61
62
63
64 |           },
          xAxis: {
            type: "category",
            data: this.xAxis,
            axisLine: { show: true, lineStyle: { color: "#e2e2e2" } },
            axisTick: {
              show: false,
            },
            axisLabel: {
 | 
| 079cb4cf  梁保满
 
即时测导出 | 65 |               color: "#333",
 | 
| 384a2a54  梁保满
 
请求头添加班主任信息,bug修改 | 66
67
68 |               interval: 0,
              width: Math.ceil(600 / this.xAxis.length),
              overflow: "breakAll"
 | 
| 77ebf04d  梁保满
 
个人版 | 69
70
71
72
73
74
75
76
77
78 |             },
          },
          yAxis: {
            type: "value",
            axisLine: { show: false },
            splitLine: {
              show: true,
            },
            axisLabel: {
              color: "#666",
 | 
| 079cb4cf  梁保满
 
即时测导出 | 79 |               formatter: function (name) {
 | 
| 22095aba  梁保满
 
接口联调 | 80 |                 return that.formatterYAxis ? `${name} %` : name
 | 
| 079cb4cf  梁保满
 
即时测导出 | 81 |               },
 | 
| 77ebf04d  梁保满
 
个人版 | 82
83
84 |             },
          },
          grid: {
 | 
| 079cb4cf  梁保满
 
即时测导出 | 85
86
87 |             top: 36,
            left: 20,
            right: 20,
 | 
| 384a2a54  梁保满
 
请求头添加班主任信息,bug修改 | 88 |             bottom: 10,
 | 
| 77ebf04d  梁保满
 
个人版 | 89
90
91
92
93
94
95 |             containLabel: true,
          },
          series: that.params.map((item) => {
            return {
              name: item.name,
              type: "line",
              symbol: "circle",
 | 
| 079cb4cf  梁保满
 
即时测导出 | 96 |               symbolSize: "6",
 | 
| 77ebf04d  梁保满
 
个人版 | 97 |               lineStyle: {
 | 
| 079cb4cf  梁保满
 
即时测导出 | 98 |                 width: 1,
 | 
| 77ebf04d  梁保满
 
个人版 | 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 |               },
              data: item.value,
            };
          }),
        };
        return options;
      },
      initData() {
        if (!this.chart) {
          const div = document.getElementById(this.id);
          this.chart = this.$echarts.init(div);
        }
        const options = this.setOption();
        this.chart?.clear();
        this.chart.setOption(options, true);
        this.chart.off("click");
        this.chart.on("click", "series", (params) => {
          // this.$emit("clickPieChart", params);
        });
      },
    },
  };
  </script>
  
  <style lang="scss" scoped>
  .chart {
    height: 100%;
  }
  </style>
 |