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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
| <template>
| <div
| class="CountryDimension"
| ref="chart"
| ></div>
| </template>
|
| <script>
| import * as echarts from "echarts"
| import { countProvinceDimension } from "@/api/screen.js"
| export default {
| data() {
| return {
| option: {},
| }
| },
| mounted() {
| this.initChart()
| },
| methods: {
| async initChart(dataPie) {
| let data = [
| {
| country: "苏丹",
| count: 1,
| },
| {
| country: "印度尼西亚",
| count: 1,
| },
| {
| country: "阿联酋",
| count: 1,
| },
| {
| country: "乌兹别克斯坦",
| count: 1,
| },
| {
| country: "哈萨克斯坦",
| count: 2,
| },
| {
| country: "委内瑞拉",
| count: 1,
| },
| {
| country: "斯里兰卡",
| count: 1,
| },
| {
| country: "中国",
| count: 17,
| },
| {
| country: "其他",
| count: 1,
| },
| {
| country: "土库曼斯坦",
| count: 1,
| },
| {
| country: "新加坡",
| count: 1,
| },
| ]
| const res = await countProvinceDimension()
| if (res.code == 200) {
| data = res.result
| }
| let xAxisData = []
| let yAxisData = []
|
| data.forEach(item => {
| xAxisData.push(item.province)
| yAxisData.push(item.count)
| })
| let option = {
| backgroundColor: "transparent",
| tooltip: {
| trigger: "axis",
| axisPointer: {
| type: "shadow",
| },
| },
| grid: {
| top: "12%",
| right: "0%",
| left: "0%",
| bottom: "13%",
| containLabel: true,
| },
| xAxis: [
| {
| type: "category",
| data: xAxisData,
| axisLine: {
| lineStyle: {
| color: "rgba(255,255,255,0.12)",
| },
| },
| interval: 0,
| axisLabel: {
| margin: 10,
| color: "#e2e9ff",
| textStyle: {
| fontSize: 11,
| },
| formatter: function (value) {
| //
| var ret = "" //拼接加\n返回的类目项
| var maxLength = 2 //每项显示文字个数
| var valLength = value.length //X轴类目项的文字个数
| var rowN = Math.ceil(valLength / maxLength) //类目项需要换行的行数
| if (rowN > 1) {
| //如果类目项的文字大于3,
| for (var i = 0; i < rowN; i++) {
| var temp = "" //每次截取的字符串
| var start = i * maxLength //开始截取的位置
| var end = start + maxLength //结束截取的位置
| //这里也可以加一个是否是最后一行的判断,但是不加也没有影响,那就不加吧
| temp = value.substring(start, end) + "\n"
| ret += temp //凭借最终的字符串
| }
| return ret
| } else {
| return value
| }
| },
| },
| },
| ],
| yAxis: [
| {
| axisLabel: {
| formatter: "{value}",
| color: "#e2e9ff",
| },
| axisLine: {
| show: false,
| },
| splitLine: {
| lineStyle: {
| color: "rgba(255,255,255,0.12)",
| },
| },
| },
| ],
| series: [
| {
| type: "bar",
| data: yAxisData,
| barWidth: "12px",
| itemStyle: {
| normal: {
| color: new echarts.graphic.LinearGradient(
| 0,
| 0,
| 0,
| 1,
| [
| {
| offset: 0,
| color: "rgba(0,244,255,1)", // 0% 处的颜色
| },
| {
| offset: 1,
| color: "rgba(0,77,167,1)", // 100% 处的颜色
| },
| ],
| false
| ),
| barBorderRadius: [20, 20, 0, 0],
| shadowColor: "rgba(0,160,221,1)",
| shadowBlur: 4,
| },
| },
| label: {
| normal: {
| show: true,
| lineHeight: 14,
| width: 40,
| height: 14,
| backgroundColor: "rgba(0,160,221,0.1)",
| borderRadius: 200,
| position: ["-8", "-20"],
| distance: 1,
| formatter: value => {
| // console.log(value);
| if (value.name == "中国") {
| return [
| ` {d|●}", " {a|${value.value}} \n", " {b|}`,
| ].join(",")
| }
| },
| // formatter: [" {d|●}", " {a|{c}} \n", " {b|}"].join(
| // ","
| // ),
| rich: {
| d: {
| color: "#3CDDCF",
| },
| a: {
| color: "#fff",
| align: "center",
| },
| b: {
| width: 1,
| height: 15,
| borderWidth: 1,
| borderColor: "#234e6c",
| align: "left",
| },
| },
| },
| },
| },
| ],
| }
|
| const chart = echarts.init(this.$refs.chart)
|
| chart.setOption(option)
| window.addEventListener("resize", function () {
| chart.resize()
| })
| },
| },
| }
| </script>
|
| <style lang="scss" scoped>
| .CountryDimension {
| width: 100%;
| height: 100%;
| }
| </style>
|
|