拖旺项目:聊城公交辅助决策系统
zhaoxing
2022-04-28 76950affed3e62fbc4e322432f874a2a797c0ba7
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
<template>
  <div :id="id" :style="{width: width, height: height}" :linec2option="linec2option"></div>
</template>
 
<script>
import * as echarts from "echarts";
 
export default {
  name: "charts",
  props: {
    //这里子组件需要接收父组件传递过来的参数
    id: {
      type: String,
    },
    width: {
      type: String,
      default: "440px",
    },
    height: {
      type: String,
      default: "310px",
    },
    linec2option: {
      type: Object,
    },
    showFont: {
      type: Boolean,
      default: true,
    },
 
  },
  data() {
    return {
      showFlag: false,
      chart: "",
 
      setOption: this.option,
    };
  },
  computed: {
    style() {
      return {
        width: this.width,
        height: this.height,
      };
    },
  },
  watch: {
    linec2option: {
      handler(newVal, oldVal) {
        if (newVal && this.chart) {
          this.chart.setOption(this.initOption());
        }
      },
      deep: true,
      immediate: true
    },
  },
  mounted() {
    this.init();
  },
  methods: {
    initOption(){
      let xdata = this.linec2option.xData;
      let data = this.linec2option.yData;
      let maxArr = this.linec2option.yData;
      return {
        grid: {
          left: "4%",
          right: "4%",
          bottom: "3%",
          top: "10%",
          containLabel: true
        },
        xAxis: {
          data: xdata,
          triggerEvent: true,
          axisTick: {
            show: false
          },
         "axisLine": {
            lineStyle: {
              color: 'rgba(255,255,255,.5)'
            },
          },
          axisLabel: {
            show: true,
            rotate: 0,
            interval: 0,
            fontSize: 12,
            color: "rgba(255, 255, 255, 0.8)"
          }
        },
        yAxis: {
          triggerEvent: true,
          nameTextStyle: {
            color: "rgba(255,255,255,1)",
            fontSize: 16,
            padding: [0, 0, 10, -20]
          },
          splitLine: {
            show: true,
            lineStyle: {
              type: 'dashed',
              color: 'rgba(62,95,137,0.3)'
            }
          },
          axisTick: {
            show: false
          },
          axisLine: {
            show: false,
            lineStyle: {
              color: 'rgba(255,255,255,.1)'
            }
          },
          axisLabel: {
            "interval": 0,
            color: '#D6F8FF',
            fontSize: 12
          }
        },
        // color: ["#e54035"],
        series: [{
          name: "数量",
          barMinHeight: 10,
          type: "pictorialBar",
          barCategoryGap: "60%",
          symbol: "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
              offset: 0,
              color: "rgba(20,131,242,0.7)"
            },
              {
                offset: 1,
                color: "rgba(21,105,189,0.3)"
              }
            ])
          },
          label: {
            show: true,
            position: "top",
            color: "#fff",
            fontSize: 12
          },
          data: data,
          z: 10
        },
          {
            name: "",
            type: "bar",
            barWidth: '20%',
            symbol: "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
            itemStyle: {
              color: "rgba(11,47,68,.1)"
            },
            data: maxArr,
            z: 9
          }
        ]
      }
    },
    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>