workJc.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <div class="workJc">
  3. <div class="echart-workJc">
  4. <div class="workJc-l">
  5. <div class="echart-yh"></div>
  6. <div class="echart-line"></div>
  7. <div class="echart-boxs" ref="ring"></div>
  8. </div>
  9. <div class="workJc-r"></div>
  10. </div>
  11. <div class="card-workJc"></div>
  12. </div>
  13. </template>
  14. <script setup lang="ts">
  15. import {ref,onMounted} from 'vue'
  16. import * as echarts from 'echarts';
  17. //获取dom节点
  18. let ring=ref()
  19. function getOption() {
  20. nextTick(() => {
  21. let color = [
  22. '#0CD2E6',
  23. '#3751E6',
  24. '#FFC722',
  25. '#886EFF',
  26. '#008DEC',
  27. '#114C90',
  28. '#00BFA5',
  29. ];
  30. let title = '自定义legend、默认选中';
  31. let legend = [
  32. 'A需求类型',
  33. 'B需求类型',
  34. 'C需求类型',
  35. 'D需求类型',
  36. 'E需求类型',
  37. '其他'
  38. ];
  39. let seriesData = [
  40. { "name": "A需求类型", "value": 30 },
  41. { "name": "B需求类型", "value": 10 },
  42. { "name": "C需求类型", "value": 15 },
  43. { "name": "D需求类型", "value": 23 },
  44. { "name": "E需求类型", "value": 10 },
  45. { "name": "其他", "value": 12 }
  46. ]
  47. let myChart = echarts.init(ring.value);
  48. let option = {
  49. backgroundColor:'#050e31',
  50. color: color,
  51. title: {
  52. top: 20,
  53. text: title,
  54. textStyle: {
  55. fontSize: 20,
  56. color: '#DDEEFF',
  57. },
  58. },
  59. grid: {
  60. top: '15%',
  61. left: 0,
  62. right: '1%',
  63. bottom: 5,
  64. containLabel: true,
  65. },
  66. legend: {
  67. orient: 'vertical',
  68. top: 'center',
  69. right: 50,
  70. textStyle: {
  71. align: 'left',
  72. verticalAlign: 'middle',
  73. rich: {
  74. name: {
  75. color: 'rgba(255,255,255,0.5)',
  76. fontSize: 10,
  77. },
  78. value: {
  79. color: 'rgba(255,255,255,0.5)',
  80. fontSize: 10,
  81. },
  82. rate: {
  83. color: 'rgba(255,255,255,0.9)',
  84. fontSize: 10,
  85. },
  86. },
  87. },
  88. data: legend,
  89. formatter: (name) => {
  90. if (seriesData.length) {
  91. const item = seriesData.filter((item) => item.name === name)[0];
  92. return `{name|${name}:}{value| ${item.value}} {rate| ${item.value}%}`;
  93. }
  94. },
  95. },
  96. series: [{
  97. name: '需求类型占比',
  98. type: 'pie',
  99. center: ['50%', '50%'],
  100. radius: ['45%', '65%'],
  101. label: {
  102. normal: {
  103. show: false,
  104. position: 'center',
  105. formatter: '{value|{c}}\n{label|{b}}',
  106. rich: {
  107. value: {
  108. padding: 5,
  109. align: 'center',
  110. verticalAlign: 'middle',
  111. fontSize: 32,
  112. },
  113. label: {
  114. align: 'center',
  115. verticalAlign: 'middle',
  116. fontSize: 16,
  117. },
  118. },
  119. },
  120. emphasis: {
  121. show: true,
  122. textStyle: {
  123. fontSize: '12',
  124. },
  125. },
  126. },
  127. labelLine: {
  128. show: false,
  129. length: 0,
  130. length2: 0,
  131. },
  132. data: seriesData,
  133. }],
  134. };
  135. myChart.setOption(option);
  136. window.onresize = function () {
  137. myChart.resize();
  138. };
  139. });
  140. }
  141. onMounted(()=>{
  142. getOption()
  143. })
  144. </script>
  145. <style lang="less" scoped>
  146. .workJc {
  147. width: 100%;
  148. height: 100%;
  149. .echart-workJc {
  150. width: 100%;
  151. height: 45%;
  152. display: flex;
  153. justify-content: space-between;
  154. align-items: center;
  155. .workJc-l {
  156. position: relative;
  157. width: 180px;
  158. height: 100%;
  159. .echart-yh {
  160. position: absolute;
  161. top: 50%;
  162. left: 50%;
  163. transform: translate(-50%, -50%);
  164. width: 100px;
  165. height: 100px;
  166. background: url('../../../../../assets/images/fire/firehome/zu-e.png') no-repeat center;
  167. background-size: 100% 100%;
  168. }
  169. .echart-line {
  170. position: absolute;
  171. top: 8%;
  172. left: 15%;
  173. width: 125px;
  174. height: 125px;
  175. background: url('../../../../../assets/images/fire/firehome/ty-e.png') no-repeat center;
  176. background-size: 100% 100%;
  177. animation: rotationLine 10s linear infinite;
  178. }
  179. @keyframes rotationLine {
  180. 0% {
  181. transform: rotate(0deg);
  182. }
  183. 100% {
  184. transform: rotate(360deg);
  185. }
  186. }
  187. .echart-boxs {
  188. position: absolute;
  189. left: 50%;
  190. top: 50%;
  191. transform: translate(-50%,-50%);
  192. width: 90px;
  193. height: 90px;
  194. }
  195. }
  196. .workJc-r{
  197. }
  198. }
  199. .card-workJc {
  200. height: 55%;
  201. border: 1px solid #ccc;
  202. }
  203. }
  204. </style>