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
| <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
| },
|
| components: {},
|
| data() {
| return {
| 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,999]
| }
| },
| computed: {
| showEchart() {
| return this.dialogVisible
| }
| },
| mounted() {
|
| setTimeout(() => {
| this.init()
| }, 500);
| },
|
| methods: {
|
| init() {
| const myChart = echarts.init(this.$refs.chart);
| var option;
|
| option = {
|
| grid: {
| bottom: '25%', // 增加底部边距,给x轴标签留出更多空间
| left: '12%'
| },
| title: {
| text: '报警类型统计', // 主标题内容
| left: 'center', // 标题居中
| textStyle: {
| color: '#333', // 标题颜色
| fontSize: 18, // 标题字体大小
| fontWeight: 'bold', // 标题字体加粗
| },
| },
| xAxis: {
| type: 'category',
| data: this.xAxisData,
| axisLabel: {
| rotate: 45, // 旋转角度
| interval: 0, // 显示所有标签
| fontSize: 12, // 缩小字体大小
| formatter: function (value) {
| return value.length > 12 ? value.substring(0, 12) + '...' : value; // 截断并显示省略号
| },
| margin: 15
| }
| },
| yAxis: {
| type: 'value'
| },
| series: [
| {
| data: this.seriesData,
| type: 'bar',
| itemStyle: {
| color: 'rgb(250,200,88)', // 设置柱状图颜色为黄色
| },
| barWidth: '35%', // 设置柱子宽度
| barCategoryGap: '30%', // 增加柱子间距
| label: {
| show: true,
| position: 'top',
| color: '#333',
| fontSize: 12,
| fontWeight: 'bold',
| },
| itemStyle: {
| color: function (params) {
| // 定义颜色数组
| const colors = ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE', '#3BA272', '#FC8452', '#9A60B4'];
| // 使用模运算循环取颜色
| return colors[params.dataIndex % colors.length];
| }
| },
| },
|
| ]
| };
|
| myChart.setOption(option);
| },
| handleClose() {
| this.$emit('closeDialog')
| }
|
| },
|
| }
|
| </script>
|
| <style scoped>
| .title {
| font-size: 18px;
|
| }
|
| .body {
| height: 650px;
| }
|
| .chart {
| height: 100%;
| }
|
| :deep(.el-dialog .el-dialog__header) {
| display: block !important;
| text-align: left;
| }
| </style>
|
|