拖旺项目:聊城公交辅助决策系统
master
2022-05-05 ff40ec1b3d0e1a75661e860b4d3e7b06498a9b43
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
<template>
  <div :id="ids" :style="{width: width, height: height}" :bar11option="bar11option"></div>
</template>
 
<script>
import * as echarts from "echarts";
 
export default {
  name: "charts",
  props: {
    //这里子组件需要接收父组件传递过来的参数
    id: {
      type: String,
    },
    width: {
      type: String,
      default: "146px",
    },
    height: {
      type: String,
      default: "168px",
    },
    bar11option: {
      type: Object,
    },
    // showFont:{
    //   type:Boolean,
    //   default: true,
    // }
  },
  data() {
    return {
      showFlag: false,
      chart: "",
      ids: this.id,
    };
  },
  computed: {
    style() {
      return {
        width: this.width,
        height: this.height,
      };
    },
  },
  watch: {
    bar11option: {
      handler(newVal, oldVal) {
        if (newVal && this.chart) {
          this.chart.setOption(this.initOption());
        }
      },
      deep: true,
      immediate: true,
    },
  },
  created() {
  },
  mounted() {
    this.init();
  },
  methods: {
    initOption() {
      return {
        animation: true,
        grid: {
          top: "5%",
          bottom: "10%",
          right: "5%",
          left: '12%'
        },
        xAxis: {
          data: this.bar11option.xData,
          axisLine: {
            show: true, //隐藏X轴轴线
            lineStyle: {
              color: "rgba(255, 255, 255, 0.8)",
              width: 1
            }
          },
          axisTick: {
            show: false //隐藏X轴轴线
          },
          splitLine: {
            show: false,
            lineStyle: {
              color: "rgba(77, 128, 254, 0.1)",
              width: 2
            }
          },
          axisLabel: {
            show: true,
            margin: 14,
            fontSize: 12,
            color: "rgba(255, 255, 255, 0.7)" //X轴文字颜色
          }
        },
        yAxis: [
          {
            type: "value",
            gridIndex: 0,
            min: 0,
            splitLine: {
              show: true,
              lineStyle: {
                color: "rgba(255, 255, 255, 0.1)",
                width: 1
              }
            },
            axisTick: {
              show: false
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "rgba(255, 255, 255, 0.8)"
              }
            },
            axisLabel: {
              show: true,
              margin: 14,
              fontSize: 12,
              color: "rgba(255, 255, 255, 0.8)"
            }
          }
        ],
        series: [
          {
            name: "客流总量",
            type: "bar",
            barWidth: 16,
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "rgba(146, 225, 255, 1)"
                },
                {
                  offset: 1,
                  color: "rgba(0, 151, 251, 1)"
                }
              ])
            },
            data: this.bar11option.yData,
            z: 10,
            zlevel: 0
          },
          {
            // 分隔
            type: "pictorialBar",
            itemStyle: {
              color: "#0F375F"
            },
            symbolRepeat: "fixed",
            symbolMargin: 2,
            symbol: "rect",
            symbolClip: true,
            symbolSize: [18, 2],
            symbolPosition: "start",
            symbolOffset: [1, 1],
            data: this.bar11option.yData,
            width: 2,
            z: 0,
            zlevel: 1
          },
        ],
        dataZoom: [
          {
            type: "slider",
            show: false,
            xAxisIndex: [0],
            endValue: 4,
            startValue: 0
          }
        ]
      };
    },
    init() {
      if (!document.getElementById(this.id)) {
        return;
      }
 
      this.chart = echarts.init(document.getElementById(this.id));
      this.chart.setOption(this.initOption());
    },
  },
};
</script>