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
| <template>
| <el-dialog :visible.sync="showEchart" width="50%" :before-close="handleClose">
| <template v-slot:title>
| <!-- <B class="title">智能数据</B> -->
| </template>
| <div class="body">
| <div ref="chart" v-if="seriesData.length" class="chart"></div>
| <el-empty v-else description="暂无数据"></el-empty>
| </div>
| </el-dialog>
| </template>
|
| <script>
| import * as echarts from "echarts";
| export default {
| name: '',
| props: {
| dialogVisible: Boolean,
| alarm_echart_data: Array,
| xAxisData: Array,
| seriesData: Array
| },
|
| data() {
| return {
| // xAxisData: ['测试超过十二字是否会被遮挡', '场景2', '场景13', '场景14', '场景15','ss'],
| // seriesData: [10, 20, 20, 34, 5,88]
| // xAxisData: ['测试超过十二字是否会被遮挡', '场景2', '场景13', '场景14', '场景15', '场景1212', '场景16', '场景17', '场景177', '场景11', '场景121', '场景16', '场景17', '场景177', '场景11', '场景121'],
| // seriesData: [10, 20, 20, 34, 5, 6, 67, 77, 12, 90, 6, 67, 77, 12, 90, 99]
| }
| },
| computed: {
| showEchart() {
| return this.dialogVisible
| }
| },
| mounted() {
| setTimeout(() => {
| this.init()
| }, 500);
| },
|
| methods: {
| init() {
| const myChart = echarts.init(this.$refs.chart);
| var option;
| option = {
| title: {
| text: '报警类型统计',
| left: 'center',
| textStyle: {
| color: '#333',
| fontSize: 18,
| fontWeight: 'bold',
| },
| },
| tooltip: {
| trigger: 'axis',
| axisPointer: {
| type: 'shadow'
| }
| },
| grid: {
| left: '3%',
| right: '4%',
| bottom: '3%',
| containLabel: true
| },
| yAxis: {
| type: 'category',
| data: this.xAxisData,
| axisLabel: {
| fontSize: 12,
| formatter: function (value) {
| return value.length > 12 ? value.substring(0, 12) + '...' : value;
| },
| margin: 10
| }
| },
| xAxis: {
| type: 'value'
| },
| series: [
| {
| data: this.seriesData,
| type: 'bar',
| itemStyle: {
| color: function (params) {
| const colors = ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE', '#3BA272', '#FC8452', '#9A60B4'];
| return colors[params.dataIndex % colors.length];
| }
| },
| barWidth: this.xAxisData.length <= 5 ? '30%' : '60%',
| label: {
| show: true,
| position: 'right',
| color: '#333',
| fontSize: 12,
| fontWeight: 'bold',
| },
| }
| ]
| };
|
| myChart.setOption(option);
| window.addEventListener('resize', function () {
| myChart.resize();
| });
| },
| handleClose() {
| this.$emit('closeDialog')
| }
| }
| }
| </script>
|
| <style scoped>
| .title {
| font-size: 18px;
| }
|
| .body {
| height: 650px;
| }
|
| .chart {
| height: 100%;
| width: 100%;
| }
|
| :deep(.el-dialog .el-dialog__header) {
| display: block !important;
| text-align: left;
| }
| </style>
|
|