Xxxu
2020-07-03 1ac6ef52a03f25f9def9f6a2594d2a8196aa77f6
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>
        <div id='chart' style='height:150px;width:100%'></div>
    </div>
</template>
<script>
import echarts from 'echarts'
export default {
  data () {
    return {
      onlineNum: 0,
      outlineNum: 0
    }
  },
  activated () {
    this.getOnlineCamera()
  },
  methods: {
    getOnlineCamera () {
      this.$http({
        url: this.$http.adornUrl('/pole/polecamera/getOnline'),
        method: 'get'
      }).then(({data}) => {
        var onlineList = data.list // 将所有数据保存
        this.onlineNum = 0
        this.outlineNum = 0
        for (var i = 0; i < onlineList.length; i++) {
          if (onlineList[i].onlineStatus === 1) {
            this.onlineNum++
          } else {
            this.outlineNum++
          }
        }
        this.drawChart()
      })
    },
    drawChart () {
      var option = {
        color: ['#09BAFE', '#FC0A15'],
        title: {
          text: '摄像头/台',
          left: 'center',
          top: '45%',
          textStyle: {
            color: 'white',
            fontSize: 13,
            align: 'center'
          }
        },
 
        graphic: [
          {
            type: 'group',
            left: '15%',
            top: '15%',
            children: [
              {
                type: 'text',
                z: 100,
                style: {
                  fill: '#FC0A15',
                  text: [this.outlineNum].join('\n'),
                  font: '14px Microsoft YaHei'
                }
              }
            ]
          },
          {
            type: 'group',
            left: '70%',
            top: '15%',
            children: [
              {
                type: 'text',
                z: 100,
                left: 50,
                top: 500,
                style: {
                  fill: '#09BAFE',
                  text: [this.onlineNum].join('\n'),
                  font: '14px Microsoft YaHei'
                }
              }
            ]
          }
        ],
 
        tooltip: {
          trigger: 'item',
          // formatter: '{a} <br/>{b}: {c} ({d}%)',
          formatter: '{a} <br/>{b}: {c}',
          position: function (point, params, dom, rect, size) {
            // 其中point为当前鼠标的位置,size中有两个属性:viewSize和contentSize,分别为外层div和tooltip提示框的大小
            var x = point[0] //
            var y = point[1]
            var boxWidth = size.contentSize[0]
            var boxHeight = size.contentSize[1]
            var posX = 0 // x坐标位置
            var posY = 0 // y坐标位置
 
            if (x < boxWidth) {
              // 左边放不开
              posX = 5
            } else {
              // 左边放的下
              posX = x - boxWidth
            }
 
            if (y < boxHeight) {
              // 上边放不开
              posY = 5
            } else {
              // 上边放得下
              posY = y - boxHeight
            }
 
            return [posX, posY]
          }
        },
        series: [
          {
            name: '摄像头在线数量',
            type: 'pie',
            radius: ['55%', '70%'],
            avoidLabelOverlap: false,
            label: {
              normal: {
                show: false
              },
              emphasis: {
                show: false,
                textStyle: {
                  fontSize: '5',
                  fontWeight: 'bold'
                }
              }
            },
            labelLine: {
              normal: {
                show: false
              }
            },
            data: [{ value: this.onlineNum, name: '在线' }, { value: this.outlineNum, name: '不在线' }]
          }
        ]
      }
 
      var echart = echarts.init(document.getElementById('chart'))
      echart.setOption(option)
    }
  }
}
</script>
<style>
</style>