拖旺项目:聊城公交辅助决策系统
master
2022-04-27 493930a42a2ea3e13905ffd8772cdb945baa7bcf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<template>
  <div :id="id" :style="{width: width, height: height}"></div>
</template>
 
<script>
  import {setDispatchTip} from "@/components/echart/methods";
  import * as echarts from "echarts";
export default {
  name: "charts",
  props: {
    //这里子组件需要接收父组件传递过来的参数
    id: {
      type: String,
      default:()=>'operateline4'
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "200px",
    },
    option: {
      type: Object,
    },
  },
  data() {
    return {
      chart: '',
      timer: null,
    };
  },
  watch: {
    option: {
      handler(newVal, oldVal) {
        if(newVal && this.chart){
          this.chart.setOption(this.initOption());
          this.timer = setDispatchTip(this.chart, this.option.xData.length, this.timer);
 
        }
      },
      deep: true,
    },
  },
  created() {
    console.log(this.option, 'option');
    
  },
  activated() {
    this.timer = setDispatchTip(this.chart, this.option.xData.length, this.timer);
  },
  deactivated() {
    clearInterval(this.timer);
    this.timer = null;
  },
  mounted() {
    this.init();
  },
  methods: {
    initOption(){
      return {
        tooltip: {
          show: true,
          trigger: "axis",
          borderWidth: 2,
          axisPointer: {
            type: 'line',
            lineStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [{
                  offset: 0, color: 'rgba(0,255,222,0.2)'
                }, {
                  offset: 0.4, color: 'rgba(0,255,222,0.2)' // 100% 处的颜色
                }, {
                  offset: 0.5, color: 'rgba(176,196,222,0.5)' // 100% 处的颜色
                }, {
                  offset: 0.6, color: 'rgba(0,255,222,0.2)' // 100% 处的颜色
                }, {
                  offset: 1, color: 'rgba(0,255,222,0.2)' // 100% 处的颜色
                }],
                global: false // 缺省为 false,
              },
              width: 20,
              type: 'solid',
            }
          },
          formatter: '{b0}<br />{a0}:{c0}%<br />{a1}:{c1}%<br />{a2}:{c2}%<br />',
          backgroundColor: "rgba(0,255,222,0.2)", //设置背景图片 rgba格式
          color: "#fff",
          borderColor: "transparent", //设置边框颜色
          textStyle: {
            color: "#fff", //设置文字颜色
          },
        },
        legend: {
          data: this.option.title,
          //   icon: "circle",
          right: 20,
          top: 5,
          textStyle: {
            color: "#88A7D2",
            fontSize: 14,
          },
        },
        grid: {
          left: '3%',
          right: '6%',
          bottom: '5%',
          top: '20%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,//坐标轴两边留白
          data: this.option.xData,
          axisLabel: { //坐标轴刻度标签的相关设置。
            interval: 0,//设置为 1,表示『隔一个标签显示一个标签』
            //    margin:15,
            textStyle: {
              color: '#fff',
              fontStyle: 'normal',
              fontFamily: '微软雅黑',
              fontSize: 12,
            },
 
            //rotate:50,
          },
          axisTick:{//坐标轴刻度相关设置。
            show: false,
          },
          axisLine:{//坐标轴轴线相关设置
            lineStyle:{
              color:'#3E5F89',
              // opacity:0.2
            }
          },
          splitLine: { //坐标轴在 grid 区域中的分隔线。
            show: true,
            lineStyle: {
              color: '#3E5F89',
              type:'dashed',
              opacity:0.3
            }
          }
        },
        yAxis: [
          {
            type: 'value',
            splitNumber: 5,
            axisLabel: {
              textStyle: {
                color: '#a8aab0',
                fontStyle: 'normal',
                fontFamily: '微软雅黑',
                fontSize: 12,
              }
            },
            axisLine:{
              show: true
            },
            axisTick:{
              show: false
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: '#3E5F89',
                type:'dashed',
                opacity:0.3
              }
            },
 
          }
        ],
        series: [
          {
            smooth: true,
            name: this.option.title[0] || '',
            type: 'line',
            itemStyle: {
              normal: {
                color:'rgba(255,217,130,1)',
                lineStyle: {
                  color: "rgba(255,217,130,1)",
                  width:1
                },
                areaStyle: {
                  color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                    offset: 0,
                    color: 'rgba(58,132,255,0)'
                  }, {
                    offset: 1,
                    color: 'rgba(58,132,255,0.35)'
                  }]),
                }
              }
            },
            data: this.option.yData.length>0?this.option.yData[0]:[],
          },
          {
            name:  this.option.title[1] || '',
            type: 'line',
            itemStyle: {
              normal: {
                color:'rgba(20,131,242,1)',
                lineStyle: {
                  color: "rgba(20,131,242,1)",
                  width:1
                },
                areaStyle: {
                  color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                    offset: 0,
                    color: 'rgba(20,131,242,0)'
                  }, {
                    offset: 1,
                    color: 'rgba(20,131,242,0.35)'
                  }]),
                }
              }
            },
            data: this.option.yData.length>1?this.option.yData[1]:[],
          },
          {
            name: this.option.title[2] || '',
            type: 'line',
            itemStyle: {
              normal: {
                color:'rgba(7,222,254,1)',
                lineStyle: {
                  color: "rgba(7,222,254,1)",
                  width:1
                },
                areaStyle: {
                  color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                    offset: 0,
                    color: 'rgba(86,237,219,0)'
                  }, {
                    offset: 1,
                    color: 'rgba(86,237,217,0.35)'
                  }]),
                }
              }
            },
            data: this.option.yData.length>2?this.option.yData[2]:[],
          }
        ]
      };
    },
    init() {
      this.chart = echarts.init(document.getElementById(this.id));
      this.chart.setOption(this.initOption());
      window.addEventListener('resize', this.chart.resize)
    },
  },
};
</script>