拖旺项目:聊城公交辅助决策系统
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
<template>
  <div :id="id" :style="{width:width,height:height}"></div>
</template>
 
<script>
import * as echarts from "echarts";
 
export default {
  name: 'bar6',
  data() {
    return {
      chart: ''
    }
  },
  props: {
    //这里子组件需要接收父组件传递过来的参数
    id: {
      type: String,
      default: 'bar5'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '250px',
    },
    options: {
      type: Object,
      default: () => {
      }
    },
    imageSize: {
      type: Number,
      default: 140
    },
 
    showFlag: {
      type: Boolean,
      default: true
    },
  },
  watch: {
    options: {
      handler(newVal) {
        if (newVal && this.chart) {
          this.chart.setOption(this.initOption());
        }
      },
    }
  },
  mounted() {
    this.init();
  },
  deactivated() {
    window.removeEventListener('resize', this.chart.resize)
  },
  methods: {
    initOption() {
      return {
        title: [
          {
            text: (this.options.value * 100).toFixed(0) + '%',
            left: '47%',
            top: '44%',
            textAlign: 'center',
            textStyle: {
              fontSize: '20',
              fontWeight: '400',
              color: '#fff',
              textAlign: 'center',
              textBorderColor: 'rgba(0, 0, 0, 0)',
              textShadowColor: '#000',
              textShadowBlur: '0',
              textShadowOffsetX: 0,
              textShadowOffsetY: 1,
            },
          },
        ],
        polar: {
          radius: ['40%', '30%'],
          center: ['50%', '50%'],
        },
        angleAxis: {
          max: 100,
          clockwise: false,
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          splitLine: {
            show: false,
          },
        },
        radiusAxis: {
          type: 'category',
          show: true,
          axisLabel: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        series: [
 
          {
            name: '',
            type: 'bar',
            roundCap: true,
            z: 2,
            showBackground: true,
            backgroundStyle: {
              color: '#15181e',
            },
            data: [this.options.value * 100],
            coordinateSystem: 'polar',
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, .5, 1, [
                  {
                    offset: 0,
                    color: this.options.color0,
                  },
                  // {
                  //    offset: .7,
                  //    color: '#5073fb',
                  // },
                  {
                    offset: 1,
                    color: this.options.color1,
                  },
                ]),
              },
            },
          },
        ],
      };
    },
    init() {
      this.chart = echarts.init(document.getElementById(this.id))
      this.chart.setOption(this.initOption());
      window.addEventListener("resize", this.chart.resize);
    }
  }
}
</script>
 
<style>
 
</style>