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
|
| <template>
| <div class="echarts-box" id="sizeBarChart"></div>
| </template>
|
| <script>
| export default {
| data () {
| return {
| myChart: null
| }
| },
|
| methods: {
| getctoduihuakuang (params) {
| this.$emit("childEvent_zhu", params, '实时监控数据')
| },
| initEcharts (params) { },
|
| createBarChart (chartData) {
| if (!this.myChart) {
| this.myChart = this.$echarts.init(
| document.getElementById("sizeBarChart")
| )
| } else {
| // 清除点击事件很重要不然会累计很多,导致点击一次调用n次的情况
| this.myChart.off('click')
| }
| let data1 = []
| let data2 = []
| let categories = []
| if (chartData.length == 0) return
| chartData.forEach(item => {
| data1.push({ value: item.shouldNum == -1 ? 0 : item.shouldNum, deptId: item.deptId, type: '应到', companyName: item.deptName })
| data2.push({ value: item.realNum == -1 ? 0 : item.realNum, deptId: item.deptId, type: '实到', companyName: item.deptName })
| categories.push(item.deptName)
| })
|
| // 指定图表的配置项和数据
| var option = {
| legend: {
| data: ["应到", "实到"],
| textStyle: {
| color: "white" // 更改图例文本颜色
| },
| top: "0%"
| },
| grid: {
| left: "10%", // 设置图表左边距
| top: "15%",
| bottom: "30%",
| },
| xAxis: {
| type: "category",
| data: categories,
| axisLabel: {
| rotate: 45,
| textStyle: {
| color: "#ffffff", // 设置x轴标签字体颜色
| fontSize: 12
| }
| }
| },
| yAxis: {
| axisLabel: {
| textStyle: {
| color: "#ffffff" // 设置y轴标签字体颜色
| }
| },
| minInterval: 1
| },
| series: [
| {
| name: "应到",
| type: "bar",
| data: data1,
| itemStyle: {
| color: "#0895E0"
| }
| },
| {
| name: "实到",
| type: "bar",
| data: data2,
| itemStyle: {
| color: "#F6DE81"
| }
| }
| ]
| }
|
| this.myChart.setOption(option)
| this.myChart.on("click", params => {
| this.getctoduihuakuang(params)
| })
| }
| }
| }
| </script>
|
| <style lang="scss" scoped>
| .echarts-box {
| width: 100%;
| height: 200px;
| }
| </style>
|
|