wordcloud.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="card_visitor_star">
  3. <div ref="chartcloud" style="width: 100%;height: 100%;"></div>
  4. </div>
  5. </template>
  6. <script setup>
  7. import * as echarts from 'echarts'
  8. const props = defineProps({
  9. resultData: {
  10. type: Array,
  11. default: []
  12. }
  13. })
  14. const chartcloud = ref(null);
  15. let chartDom = null;
  16. const initAccess = () => {
  17. let result = props.resultData
  18. chartDom = echarts.init(chartcloud.value);
  19. let style = {
  20. width: 32,
  21. height: 24,
  22. padding: [5, 6, 0, 0],
  23. fontSize: 20,
  24. align: "center",
  25. color: "#ffffff"
  26. }
  27. let option = {
  28. tooltip: {
  29. trigger: "axis",
  30. backgroundColor: "rgba(9,40,84,0.8)",
  31. borderColor: "rgba(9,40,84,0.8)",
  32. textStyle: {
  33. fontSize: 20,
  34. color: "#fff",
  35. },
  36. axisPointer: {
  37. type: "shadow",
  38. },
  39. formatter: function (params) {
  40. return (
  41. params[0].name +
  42. "&nbsp;&nbsp;&nbsp;&nbsp;<span style='font-weight:bold;color:'#fff'>" +
  43. params[0].value +
  44. "</span>"
  45. );
  46. },
  47. },
  48. grid: {
  49. left: "5%",
  50. right: "5%",
  51. top: "10%",
  52. bottom: "20%", // 特殊
  53. containLabel: true,
  54. },
  55. xAxis: [
  56. {
  57. type: "value",
  58. show: false,
  59. },
  60. ],
  61. yAxis: [
  62. {
  63. type: "category",
  64. splitLine: {
  65. show: false,
  66. },
  67. axisLine: {
  68. show: false,
  69. },
  70. axisTick: {
  71. show: false,
  72. },
  73. inverse: true,
  74. data: result.map((item) => item.department_name),
  75. axisLabel: {
  76. color: "rgba(239, 242, 250, 1)",
  77. margin: 10,
  78. rich: {
  79. ids: {
  80. padding: [0, 0, 0, 2],
  81. fontSize: 16,
  82. color: '#b4bec8',
  83. },
  84. nameStyle: {
  85. padding: [0, 10, 0, 2],
  86. fontSize: 16,
  87. color: '#fff',
  88. },
  89. rank: {
  90. ...style,
  91. backgroundColor: new echarts.graphic.LinearGradient(0, 1, 1, 1, [
  92. {
  93. offset: 0,
  94. color: '#E7F4FF',
  95. },
  96. {
  97. offset: 0.95,
  98. color: '#fff',
  99. },
  100. ]),
  101. },
  102. rank1: {
  103. ...style,
  104. color: "#FF992B",
  105. backgroundColor: new echarts.graphic.LinearGradient(0, 1, 1, 1, [
  106. {
  107. offset: 0,
  108. color: '#E7F4FF',
  109. },
  110. {
  111. offset: 0.95,
  112. color: '#fff',
  113. },
  114. ]),
  115. },
  116. },
  117. },
  118. },
  119. {
  120. inverse: true,
  121. axisTick: "none",
  122. axisLine: "none",
  123. show: true,
  124. axisLabel: {
  125. color: "rgba(239, 242, 250, 1)",
  126. fontSize: 15,
  127. margin: 10,
  128. formatter: function (value) {
  129. return value;
  130. },
  131. },
  132. data: result.map((item) => item.count),
  133. },
  134. ],
  135. series: [
  136. {
  137. type: "bar",
  138. barWidth: 10, // 柱子宽度
  139. MaxSize: 0,
  140. showBackground: true,
  141. backgroundStyle: {
  142. color: "rgb(10, 51, 126)",
  143. borderRadius: 5, //设置背景的圆角
  144. },
  145. data: result.map((item) => item.count).map((item) => {
  146. return {
  147. value: item,
  148. itemStyle: {
  149. borderRadius: 5,
  150. color: "#069DFD",
  151. },
  152. };
  153. }),
  154. },
  155. {
  156. type: 'scatter',
  157. emphasis: {
  158. scale: false
  159. },
  160. symbol: 'rect',
  161. itemStyle: {
  162. barBorderRadius: [30, 0, 0, 30],
  163. color: '#fff',
  164. shadowColor: '#fff',
  165. shadowBlur: 1,
  166. borderWidth: 1,
  167. opacity: 1
  168. },
  169. symbolSize: [4, 10], // 进度条白点的大小
  170. z: 2,
  171. data: result.map((item) => item.count),
  172. },
  173. ],
  174. };
  175. chartDom.setOption(option)
  176. };
  177. // 生命周期
  178. onMounted(() => {
  179. initAccess()
  180. });
  181. // 窗口自适应
  182. window.addEventListener('resize', () => {
  183. chartDom?.resize();
  184. });
  185. </script>
  186. <style scoped lang="scss">
  187. .card_visitor_star {
  188. width: 100%;
  189. height: 100%;
  190. display: flex;
  191. flex-direction: column;
  192. }
  193. </style>