district.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div class="person_box">
  3. <div ref="chartDistrict" style="width: 100%;height: 100%;"></div>
  4. </div>
  5. </template>
  6. <script setup>
  7. import * as echarts from 'echarts'
  8. defineProps({
  9. title: {
  10. type: String,
  11. default: '暂无数据'
  12. }
  13. })
  14. const chartDistrict = ref(null);
  15. let chartDom = null;
  16. const initAccess = () => {
  17. let colorList = [
  18. "rgba(255, 38, 38, 1)",
  19. "rgba(255, 96, 0, 1)",
  20. "rgba(255, 165, 7, 1)",
  21. "rgba(0, 234, 255, 1)",
  22. "rgba(0, 132, 255, 1)",
  23. "#2379FF",
  24. ];
  25. let colorListA = [
  26. "rgba(255, 38, 38, 0.1)",
  27. "rgba(255, 96, 0, 0.1)",
  28. "rgba(255, 165, 7, 0.1)",
  29. "rgba(0, 234, 255, 0.1)",
  30. "rgba(0, 132, 255, 0.1)",
  31. "#49B1FF",
  32. ];
  33. let colorListB = [
  34. "rgba(249, 136, 136, 1)",
  35. "rgba(255, 162, 106, 1)",
  36. "rgba(255, 210, 130, 1)",
  37. "rgba(142, 255, 206, 1)",
  38. "rgba(165, 232, 255, 1)",
  39. ];
  40. let colorListC = [
  41. "rgba(249, 136, 136, 0.1)",
  42. "rgba(255, 162, 106, 0.1)",
  43. "rgba(255, 210, 130, 0.1)",
  44. "rgba(142, 255, 206, 0.1)",
  45. "rgba(165, 232, 255, 0.1)",
  46. ];
  47. let result = [
  48. { name: "天水祥丰农资农贸有限公司", value: 86 },
  49. { name: "天水花牛苹果", value: 83 },
  50. { name: "天水红富士", value: 73 },
  51. { name: "天水金帅苹果", value: 61 },
  52. { name: "天水黄面皮", value: 61 },
  53. ];
  54. chartDom = echarts.init(chartDistrict.value);
  55. let option = {
  56. color: colorList,
  57. tooltip: {
  58. show: true,
  59. trigger: "item",
  60. axisPointer: {
  61. type: "shadow",
  62. textStyle: {
  63. color: "#fff",
  64. },
  65. },
  66. textStyle: {
  67. color: "#fff",
  68. },
  69. backgroundColor: "rgba(16, 123, 184, .52)", //设置背景颜色
  70. borderColor: "rgba(255, 255, 255, 0)",
  71. confine: true,
  72. formatter: "{b}<br />客流指数: {c}",
  73. },
  74. legend: {
  75. show: false,
  76. },
  77. grid: {
  78. left: "2%",
  79. right: "2%",
  80. top: "6%",
  81. bottom: "0%",
  82. },
  83. xAxis: [
  84. {
  85. splitLine: {
  86. show: false,
  87. },
  88. type: "value",
  89. show: false,
  90. },
  91. ],
  92. yAxis: [
  93. {
  94. splitLine: {
  95. show: false,
  96. },
  97. axisLine: {
  98. show: false,
  99. },
  100. type: "category",
  101. axisTick: {
  102. show: false,
  103. },
  104. inverse: true,
  105. data: result.map((item) => item.name),
  106. axisLabel: {
  107. fontSize: 14,
  108. inside: true,
  109. formatter: (name, index) => {
  110. const id = index + 1;
  111. return `{count${id}|${id}}`;
  112. },
  113. rich: {
  114. count1: {
  115. padding: [0, 0, 33, 0],
  116. align: "center",
  117. color: colorList[0],
  118. fontSize: 14,
  119. fontFamily: "Source Han Sans CN",
  120. },
  121. count2: {
  122. padding: [0, 0, 33, 0],
  123. align: "center",
  124. color: colorList[1],
  125. fontSize: 14,
  126. fontFamily: "Source Han Sans CN",
  127. },
  128. count3: {
  129. padding: [0, 0, 33, 0],
  130. align: "center",
  131. color: colorList[2],
  132. fontSize: 14,
  133. fontFamily: "Source Han Sans CN",
  134. },
  135. count4: {
  136. padding: [0, 0, 33, 0],
  137. align: "center",
  138. color: colorList[3],
  139. fontSize: 14,
  140. fontFamily: "Source Han Sans CN",
  141. },
  142. count5: {
  143. padding: [0, 0, 33, 0],
  144. align: "center",
  145. color: colorList[4],
  146. fontSize: 14,
  147. fontFamily: "Source Han Sans CN",
  148. },
  149. },
  150. },
  151. },
  152. {
  153. type: "category",
  154. inverse: true,
  155. axisTick: "none",
  156. axisLine: "none",
  157. show: true,
  158. axisLabel: {
  159. textStyle: {
  160. color: "#fff",
  161. fontSize: 12,
  162. },
  163. verticalAlign: "bottom",
  164. padding: [0, 5, 10, 0],
  165. inside: true,
  166. formatter: function (value) {
  167. return `{name|客流指数:}{value|${value}}`;
  168. },
  169. rich: {
  170. name: {
  171. align: "center",
  172. color: "#D3E5FF",
  173. fontSize: 14,
  174. fontFamily: "Source Han Sans CN",
  175. },
  176. value: {
  177. align: "center",
  178. color: "#fff",
  179. fontSize: 14,
  180. fontFamily: "Source Han Sans CN",
  181. },
  182. },
  183. },
  184. data: result.map((item) => item.value),
  185. },
  186. ],
  187. series: [
  188. {
  189. name: "",
  190. type: "bar",
  191. barWidth: 5, // 柱子宽度
  192. MaxSize: 0,
  193. showBackground: true,
  194. barBorderRadius: [30, 0, 0, 30],
  195. backgroundStyle: {
  196. color: "rgba(50, 60, 86, 1)",
  197. },
  198. label: {
  199. show: true,
  200. offset: [40, -17],
  201. color: "#D3E5FF",
  202. fontWeight: 500,
  203. position: "left",
  204. align: "left",
  205. fontSize: 14,
  206. fontFamily: "Source Han Sans CN",
  207. formatter: function (params) {
  208. console.log(params);
  209. return params.data.name;
  210. },
  211. },
  212. data: result.map((item, index) => {
  213. return {
  214. name: item.name,
  215. value: item.value,
  216. itemStyle: {
  217. barBorderRadius: [3, 0, 0, 3],
  218. color: {
  219. type: "linear",
  220. x: 0,
  221. y: 0,
  222. x2: 1,
  223. y2: 1,
  224. colorStops: [
  225. {
  226. offset: 0,
  227. color: colorListA[index],
  228. },
  229. {
  230. offset: 1,
  231. color: colorList[index],
  232. },
  233. ],
  234. },
  235. },
  236. };
  237. }),
  238. },
  239. {
  240. name: "外圆",
  241. type: "scatter",
  242. emphasis: {
  243. scale: false,
  244. },
  245. showSymbol: true,
  246. symbol: "circle",
  247. symbolSize: 8, // 进度条白点
  248. z: 2,
  249. data: result.map((item, index) => {
  250. return {
  251. name: item.name,
  252. value: item.value,
  253. itemStyle: {
  254. color: colorListB[index],
  255. borderColor: colorListC[index],
  256. borderWidth: 12,
  257. shadowColor: colorListC[index],
  258. shadowBlur: 10,
  259. opacity: 1,
  260. },
  261. };
  262. }),
  263. animationDelay: 500,
  264. },
  265. {
  266. name: "外圆",
  267. type: "scatter",
  268. emphasis: {
  269. scale: false,
  270. },
  271. showSymbol: true,
  272. symbol: "circle",
  273. symbolSize: 3, // 进度条白点
  274. z: 3,
  275. data: result.map((item, index) => {
  276. return {
  277. name: item.name,
  278. value: item.value,
  279. itemStyle: {
  280. color: colorListB[index],
  281. borderColor: colorListC[index],
  282. borderWidth: 30,
  283. shadowColor: colorListC[index],
  284. shadowBlur: 10,
  285. opacity: 1,
  286. },
  287. };
  288. }),
  289. animationDelay: 500,
  290. },
  291. ],
  292. };
  293. chartDom.setOption(option)
  294. };
  295. // 生命周期
  296. onMounted(() => {
  297. initAccess()
  298. });
  299. // 窗口自适应
  300. window.addEventListener('resize', () => {
  301. chartDom?.resize();
  302. });
  303. </script>
  304. <style scoped lang="scss">
  305. .person_box {
  306. width: 100%;
  307. height: 100%;
  308. display: flex;
  309. align-items: center;
  310. }
  311. </style>