拖旺项目:聊城公交辅助决策系统
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
<template>
  <div :id="id" :style="{width:width,height:height}" :linec3option="linec3option"></div>
</template>
 
<script>
import * as echarts from "echarts";
 
export default {
  name: "charts",
  props: {
    //这里子组件需要接收父组件传递过来的参数
    id: {
      type: String,
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "200px",
    },
    linec3option: {
      type: Object,
    },
  },
  data() {
    return {
      chart: "",
 
    };
  },
  computed: {},
  watch: {
    linec3option: {
      handler(newVal, oldVal) {
        if (newVal && this.chart) {
          this.chart.setOption(this.initOption());
        }
      },
      immediate: true,
      deep: true,
    },
  },
  created() {
  },
  mounted() {
    this.init();
  },
  methods: {
    initOption() {
      return {
        title: {
          textStyle: {
            fontWeight: 'normal',
            fontSize: 12,
            color: '#F1F1F3'
          },
          left: '6%'
        },
        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',
            }
          },
          backgroundColor: "rgba(0,255,222,0.2)", //设置背景图片 rgba格式
          color: "#fff",
          borderColor: "transparent", //设置边框颜色
          textStyle: {
            color: "#fff", //设置文字颜色
          },
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          top: '8%',
          containLabel: true
        },
        xAxis: [{
          type: 'category',
          boundaryGap: false,
          axisLine: {
            lineStyle: {
              color: "rgba(255, 255, 255, 0.8)"
            }
          },
          axisTick: {
            show: false
          },
          data: this.linec3option.xData
        }],
        yAxis: [{
          type: 'value',
          axisTick: {
            show: false
          },
          axisLine: {
            "show": false,
            lineStyle: {
              color: '#57617B'
            }
          },
         axisLabel: {
            "interval": 0,
            color: '#D6F8FF',
            fontSize: 12
          },
         splitLine: {
            show: true,
            lineStyle: {
              type: 'dashed',
              color: 'rgba(62,95,137,0.3)'
            }
          },
        }],
        series: this.linec3option.series,
      };
    },
    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>