wordcloud.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. const color = ['#3c90ff', '#fff225', '#24ffdf', '#ff9c3c', '#7536ff']
  18. const indicator = [
  19. {
  20. text: '文明村',
  21. min: 0,
  22. max: 100
  23. },
  24. {
  25. text: '卫生村',
  26. min: 0,
  27. max: 100
  28. },
  29. {
  30. text: '森林村庄',
  31. min: 0,
  32. max: 100
  33. },
  34. {
  35. text: '全面小康',
  36. min: 0,
  37. max: 100
  38. },
  39. {
  40. text: '景区村庄',
  41. min: 0,
  42. max: 100
  43. }
  44. ]
  45. const Data = [80, 61, 70, 86, 77]
  46. function setData() {
  47. return [
  48. {
  49. value: Data,
  50. itemStyle: {
  51. normal: {
  52. lineStyle: {
  53. color: '#4BFFFC',
  54. shadowColor: '#4BFFFC',
  55. shadowBlur: 5
  56. },
  57. shadowColor: '#4BFFFC',
  58. shadowBlur: 5
  59. }
  60. },
  61. areaStyle: {
  62. normal: {
  63. // 单项区域填充样式
  64. color: {
  65. type: 'radial',
  66. x: 0.5, //右
  67. y: 0.5, //下
  68. r: 1,
  69. colorStops: [
  70. {
  71. offset: 1,
  72. color: '#4BFFFC'
  73. },
  74. {
  75. offset: 0,
  76. color: 'rgba(0,0,0,0)'
  77. }
  78. ],
  79. globalCoord: false
  80. },
  81. opacity: 0.8 // 区域透明度
  82. }
  83. }
  84. }
  85. ]
  86. }
  87. function setgauge(i) {
  88. return {
  89. type: 'gauge',
  90. detail: false,
  91. splitNumber: 10, //刻度数量
  92. radius: '80%', //图表尺寸
  93. center: ['50%', '50%'],
  94. startAngle: 90 + 72 * i + 18, //开始刻度的角度
  95. endAngle: 90 + 72 * (i + 1) - 18, //结束刻度的角度
  96. axisLine: {
  97. show: false
  98. },
  99. axisTick: {
  100. show: true,
  101. lineStyle: {
  102. color: '#66ccff',
  103. width: 1
  104. },
  105. length: 6,
  106. splitNumber: 1
  107. },
  108. splitLine: {
  109. show: false
  110. },
  111. axisLabel: {
  112. show: false
  113. }
  114. }
  115. }
  116. function setSpot() {
  117. var scatterData = []
  118. Data.map((o, i) => {
  119. scatterData.push({
  120. value: [o, i],
  121. itemStyle: {
  122. normal: {
  123. color: color[i],
  124. borderColor: '#fff',
  125. borderWidth: 1,
  126. shadowColor: color[i],
  127. shadowBlur: 8
  128. }
  129. }
  130. })
  131. })
  132. return scatterData
  133. }
  134. chartDom = echarts.init(chartDistrict.value);
  135. let option = {
  136. polar: {
  137. center: ['50%', '50%'],
  138. radius: '60%'
  139. },
  140. radar: {
  141. shape: 'circle',
  142. center: ['50%', '50%'],
  143. radius: '60%',
  144. indicator: indicator,
  145. axisName: {
  146. color: '#fff',
  147. fontSize: 16,
  148. padding: -25
  149. },
  150. nameGap: 45,
  151. splitNumber: 4,
  152. splitArea: {
  153. // 坐标轴在 grid 区域中的分隔区域,默认不显示。
  154. show: true,
  155. areaStyle: {
  156. // 分隔区域的样式设置。
  157. color: ['rgba(27, 50, 66, 0.4)']
  158. }
  159. },
  160. axisLine: {
  161. //指向外圈文本的分隔线样式
  162. lineStyle: {
  163. color: '#5aa3d0'
  164. }
  165. },
  166. splitLine: {
  167. lineStyle: {
  168. color: 'rgba(99,192,251,0.2)', // 分隔线颜色
  169. width: 2 // 分隔线线宽
  170. }
  171. }
  172. },
  173. angleAxis: {
  174. type: 'category',
  175. data: name,
  176. minInterval: 1,
  177. boundaryGap: false,
  178. clockwise: false,
  179. axisTick: {
  180. show: false
  181. },
  182. axisLabel: {
  183. show: false
  184. },
  185. axisLine: {
  186. show: false
  187. },
  188. splitLine: {
  189. show: false
  190. }
  191. },
  192. radiusAxis: {
  193. min: 0,
  194. max: 100,
  195. interval: 25,
  196. splitLine: {
  197. show: false
  198. },
  199. axisTick: {
  200. show: false
  201. },
  202. axisLine: {
  203. //指向外圈文本的分隔线样式
  204. lineStyle: {
  205. color: '#5aa3d0'
  206. }
  207. },
  208. axisLabel: {
  209. fontSize: 12,
  210. color: '#5aa3d0',
  211. align: 'left',
  212. margin: -5
  213. }
  214. },
  215. series: [
  216. setgauge(0),
  217. setgauge(1),
  218. setgauge(2),
  219. setgauge(3),
  220. setgauge(4),
  221. {
  222. type: 'radar',
  223. silent: true,
  224. lineStyle: {
  225. color: '#66ffff'
  226. },
  227. areaStyle: {
  228. color: 'rgba(102, 255, 255, 0.31)'
  229. },
  230. data: setData()
  231. },
  232. {
  233. type: 'scatter',
  234. coordinateSystem: 'polar',
  235. symbolSize: 10,
  236. data: setSpot()
  237. }
  238. ]
  239. };
  240. chartDom.setOption(option)
  241. };
  242. // 生命周期
  243. onMounted(() => {
  244. initAccess()
  245. });
  246. // 窗口自适应
  247. window.addEventListener('resize', () => {
  248. chartDom?.resize();
  249. });
  250. </script>
  251. <style scoped lang="scss">
  252. .person_box {
  253. width: 100%;
  254. height: 100%;
  255. display: flex;
  256. align-items: center;
  257. }
  258. </style>