wind-monitor.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div class="windMonitor">
  3. <div class="title-top" @click="getDetail">风量监测</div>
  4. <div class="wind-contents">
  5. <div class="wind-bar" ref="windBar"></div>
  6. </div>
  7. </div>
  8. </template>
  9. <script lang="ts" setup>
  10. import { ref, reactive, nextTick, onMounted } from 'vue';
  11. import * as echarts from 'echarts';
  12. const emit = defineEmits(['goDetail'])
  13. //获取dom节点
  14. let windBar = ref<any>();
  15. //跳转详情
  16. function getDetail() {
  17. emit('goDetail', 'windrect')
  18. }
  19. function getOption() {
  20. nextTick(() => {
  21. const data = [60, 90, 100, 50, 70, 33,];
  22. const color = '#66ffff';
  23. const barWidth = 0.1; // 柱条占比
  24. function renderItem(params, api) {
  25. const topCenter = api.coord([api.value(0), api.value(1)]); // 顶点中心
  26. const width = api.size([0, 1])[0] * barWidth; // 宽度
  27. const ballRadius = width * 0.8;
  28. return {
  29. type: 'group',
  30. children: [
  31. {
  32. // 圆形装饰
  33. type: 'circle',
  34. shape: {
  35. cx: topCenter[0],
  36. cy: topCenter[1],
  37. r: ballRadius,
  38. },
  39. style: api.style({
  40. fill: '#66ffff',
  41. stroke: color,
  42. lineWidth: 2,
  43. }),
  44. },
  45. ],
  46. };
  47. }
  48. const myChart = echarts.init(windBar.value);
  49. let option = {
  50. color: [color],
  51. tooltip: {
  52. trigger: 'item',
  53. show: true,
  54. formatter: function (p) {
  55. console.info(p);
  56. return p.marker + p.name + ' : ' + p.value;
  57. },
  58. },
  59. grid: {
  60. left: '8%',
  61. top: '15%',
  62. bottom: '15%',
  63. right: '8%',
  64. // containLabel: true
  65. },
  66. xAxis: {
  67. type: 'category',
  68. data: ['2023.1', '2023.2', '2023.3', '2023.4', '2023.5', '2023.6'],
  69. axisLabel: {
  70. formatter: '{value}',
  71. fontSize: 14,
  72. margin: 10,
  73. textStyle: {
  74. color: '#b3b8cc',
  75. },
  76. },
  77. axisLine: {
  78. lineStyle: {
  79. color: 'rgba(62, 103, 164)',
  80. },
  81. },
  82. splitLine: {
  83. show: false,
  84. },
  85. axisTick: {
  86. show: false,
  87. },
  88. },
  89. yAxis: {
  90. type: 'value',
  91. name: '(%)',
  92. max: 150,
  93. axisLabel: {
  94. textStyle: {
  95. fontSize: 14,
  96. color: '#b3b8cc',
  97. },
  98. },
  99. nameTextStyle: {
  100. color: '#fff',
  101. fontSize: 12,
  102. lineHeight: 10,
  103. },
  104. splitLine: {
  105. lineStyle: {
  106. color: 'rgba(62, 103, 164,.4)',
  107. },
  108. },
  109. axisLine: {
  110. show: false,
  111. },
  112. axisTick: {
  113. show: false,
  114. },
  115. },
  116. series: [
  117. {
  118. data: data,
  119. type: 'bar',
  120. barWidth: barWidth * 100 + '%',
  121. itemStyle: {
  122. color: {
  123. x: 0,
  124. y: 0,
  125. x2: 0,
  126. y2: 1,
  127. colorStops: [
  128. {
  129. offset: 0,
  130. color: 'rgba(85, 255, 237, 1)', // 0% 处的颜色
  131. },
  132. {
  133. offset: 1,
  134. color: 'rgba(66, 142, 255, 0.1)', // 100% 处的颜色
  135. },
  136. ],
  137. },
  138. },
  139. label: {
  140. normal: {
  141. show: true,
  142. position: ['-7', '-28'],
  143. formatter: [' {a|{c}}'].join(','),
  144. rich: {
  145. a: {
  146. color: '#fff',
  147. align: 'center',
  148. },
  149. },
  150. },
  151. },
  152. },
  153. {
  154. data: data,
  155. type: 'custom',
  156. renderItem: renderItem,
  157. zlevel: 2,
  158. },
  159. ],
  160. };
  161. myChart.setOption(option);
  162. window.onresize = function () {
  163. myChart.resize();
  164. };
  165. });
  166. }
  167. onMounted(() => {
  168. getOption();
  169. });
  170. </script>
  171. <style lang="less" scoped>
  172. .windMonitor {
  173. width: 100%;
  174. height: 100%;
  175. position: relative;
  176. .title-top {
  177. position: absolute;
  178. top: 9px;
  179. left: 46px;
  180. color: #fff;
  181. font-size: 16px;
  182. font-family: 'douyuFont';
  183. cursor: pointer;
  184. &:hover{
  185. color: #66ffff;
  186. }
  187. }
  188. .wind-contents {
  189. position: absolute;
  190. left: 0;
  191. top: 36px;
  192. width: 100%;
  193. height: calc(100% - 36px);
  194. .wind-bar {
  195. width: 100%;
  196. height: 100%;
  197. }
  198. }
  199. }
  200. </style>