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
| <!--
| * @Date: 2024-04-18 21:52:18
| * @LastEditors: lzhe lzhe@example.com
| * @LastEditTime: 2024-11-10 13:22:12
| * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/components/TimeAlarm.vue
| -->
| <template>
| <div>
| <div id="pie1" style="width: 100%;height:200px;"></div>
| <div id="pie2" style="width: 100%;height:200px;"></div>
| </div>
| </template>
|
| <script>
| import * as echarts from 'echarts';
| export default {
| props: {
| getwcsRData: {
| default: [],
| type: Array
| }
| },
| components: {
|
| },
| data() {
| return {
| option: {
| title: {
| text: '开机运行率',
| left: 'center'
| },
| tooltip: {
| trigger: 'item',
| formatter: function (params) {
| // 自定义tooltip内容,如果悬停在“其他”上,则返回空字符串
| if (params.name === '运行率') {
| return params.name + ' : ' + ' (' + params.percent + '%)';
| } else {
| return '';
| }
| }
| },
| graphic: {
| type: 'text',
| enterFrom: {
| style: { opacity: 0 }// 淡入
| },
| enterAnimation: {
| duration: 1300//动画时长
| },
| left: 'center',
| top: 'middle',
| style: {
| text: [
| '开机运行率',
| '88.00%'
| ].join('\n'),
| textAlign: 'center',
| textVerticalAlign: 'middle',
| fontSize: 12,
| fontWeight: 'bold',
| fill: '#44CD96' // 文字颜色
| }
| },
| series: [
| {
| radius: ['40%', '65%'],
| center: ['50%', '50%'],
| name: '数据来源',
| type: 'pie',
| // data: [
| // { value: 80, name: '运行率', itemStyle: { color: '#44CD96' } },
| // { value: 20, name: '其他', itemStyle: { color: '#ADB0AF' } }
| // ],
| label: { //outside注释
| show: false,
| // formatter: function(params) {
| // if(params.name == '运行率') {
| // return params.name + ':' + params.percent + '%';
| // }else {
| // return ''
| // }
| // }
| },
| emphasis: { //hover关闭高亮状态
| disabled: true,
| }
| }
| ]
| }
| }
| },
| methods: {
| query() {
| this.getwcsRData.forEach(item=> {
| if(item.name == '运行率') {
| var option = JSON.parse(JSON.stringify(this.option));
| option.title.text = "开机运行率";
| option.graphic.style.text = ['开机运行率',item.value + '%'].join('\n');
| option.series[0].data = [
| { value: item.value, name: '运行率', itemStyle: { color: item.itemStyle.color }},
| { value: (100 - item.value), name: '其他', itemStyle: { color: '#ADB0AF' }}
| ]
| var myChartPie1 = echarts.init(document.getElementById('pie1'));
| myChartPie1.setOption(option);
| }
| if(item.name == '稼动率') {
| var option = JSON.parse(JSON.stringify(this.option));
| option.title.text = "稼动率";
| option.graphic.style.text = ['稼动率',item.value + '%'].join('\n');
| option.series[0].data = [
| { value: item.value, name: '稼动率', itemStyle: { color: item.itemStyle.color }},
| { value: (100 - item.value), name: '其他', itemStyle: { color: '#ADB0AF' }}
| ]
| var myChartPie2 = echarts.init(document.getElementById('pie2'));
| myChartPie2.setOption(option);
| }
| })
| }
| },
| watch: {
| getwcsRData() {
| this.query();
| }
| },
| mounted() {
|
| }
| }
| </script>
|
| <style lang="scss" scoped></style>
|
|