拖旺项目:聊城公交辅助决策系统
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
<template>
  <div :id="id" :style="{width:width,height:height}" :linec8option="linec8option"></div>
</template>
 
<script>
import * as echarts from "echarts";
 
export default {
  name: "linec8",
  props: {
    //这里子组件需要接收父组件传递过来的参数
    id: {
      type: String,
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "200px",
    },
    linec8option: {
      type: Object,
      default: () => {}
    },
  },
  data() {
    return {
      chart: "",
    };
  },
  watch: {
    linec8option: {
      handler(newVal, oldVal) {
        if (newVal && this.chart) {
          this.chart.setOption(this.initOption());
        }
      },
      immediate: true,
      deep: true,
    },
  },
  created() {
  },
  mounted() {
    this.init();
  },
  methods: {
    initOption() {
      return {
        grid: [
          {
            left: '15%',
            top: '5%',
            bottom: '10%',
            right: '5%',
 
          },
          {
            left: '15%',
            top: '5%',
            bottom: '10%',
            right: '5%',
 
          }
        ],
        xAxis: [
          {
            splitNumber: 8,
            axisLine: {
              lineStyle: {
                show: true,
                color: "rgba(255, 255, 255, 0.8)"
              }
            },
            axisTick: {
              show: true,
              inside: false,
              lineStyle: {
                color: '#10899A',
                fontSize: 14,
                fontFamily: 'PingFangSC',
                fontWeight: 300
              }
            },
            splitLine: {
              show: false
            },
            axisLabel: {
              formatter: (params) => {
                return '{marginTop|' + params + '}';
              },
              rich: {
                marginTop: {
                  padding: [0, 0, 0, 0],
                  color: 'rgb(255,255,255,0.8',
                  fontSize: 14,
                  fontFamily: 'PingFangSC',
                  fontWeight: 300
 
                }
              }
            },
          },
          {
            gridIndex: 1,
            show: true,
            offset: 13,
            axisLine: {
              lineStyle: {
                color: '#10899A'
              }
            }
          }
        ],
        yAxis: [
          {
            name: '年/月',
            data: [],
 
            nameTextStyle: {
              color: '#06D3CD',
              fontSize: 14,
              fontFamily: 'PingFangSC',
              fontWeight: 300,
              padding: [0, 0, 8, 0]
            },
            axisLine: {
              lineStyle: {
                color: 'rgb(255,255,255,0.8',
              },
              textStyle: {
                color: 'rgb(255,255,255,0.8',
              }
            },
            axisTick: {
              lineStyle: {
                color: '#10899A',
                fontSize: 14,
                fontFamily: 'PingFangSC',
                fontWeight: 300
              }
            }
 
          }, {
            gridIndex: 1,
            data: this.linec8option.xData,
            position: 'left',
            nameTextStyle: {
              color: 'red',
              padding: [0, 0, 0, 8],
              fontSize: 14,
              fontFamily: 'PingFangSC',
              fontWeight: 300
            },
            axisLabel: {
              formatter: (params) => {
                return '{marginTop|' + params + '}';
              },
              rich: {
                marginTop: {
                  padding: [0, 0, 0, 0],
                  color: 'rgb(255,255,255,0.8',
                  fontSize: 14,
                  fontFamily: 'PingFangSC',
                  fontWeight: 300
 
                }
              }
            },
            axisTick: {
              show: false
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgb(255,255,255,0.8',
              }
            },
            splitLine: {
              show: false,
            }
          }],
        series: [{
          name: '订单数量',
          type: 'bar',
          itemStyle: {
            // barBorderRadius: 10,
            color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
              offset: 0,
              color: 'rgba(22,134,246,0)'
            },
              {
                offset: 1,
                color: 'rgba(0,206,217,1)'
              }
            ])
          },
          barWidth: 10,
          data: this.linec8option.yData
        }]
      };
    },
    init() {
      if (!document.getElementById(this.id)) {
        return;
      }
 
      this.chart = echarts.init(document.getElementById(this.id));
      this.chart.setOption(this.initOption());
      window.addEventListener("resize", this.chart.resize);
    },
  },
};
</script>