switchAll.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class="_switchAll">
  3. <HeadlineTag type="right" value="运行分析(周)"></HeadlineTag>
  4. <div class="_switchAll_mains">
  5. <div ref="chartRef" style="width: 100%; height: 100%;"></div>
  6. </div>
  7. </div>
  8. </template>
  9. <script setup>
  10. import { ref, onMounted, onUnmounted } from 'vue';
  11. import * as echarts from 'echarts';
  12. import HeadlineTag from '@/components/HeadlineTag';
  13. const chartRef = ref(null);
  14. let chart = null;
  15. const generateRandomData = (length, max) => {
  16. const randomData = [];
  17. for (let i = 0; i < length; i++) {
  18. randomData.push(Math.floor(Math.random() * max));
  19. }
  20. return randomData;
  21. };
  22. const handleResize = () => {
  23. if (chart) {
  24. chart.resize();
  25. }
  26. };
  27. onMounted(() => {
  28. if (chartRef.value) {
  29. chart = echarts.init(chartRef.value);
  30. const option = {
  31. title: null,
  32. tooltip: {
  33. trigger: 'axis'
  34. },
  35. legend: false,
  36. // 调整 grid 配置以在 Y 轴方向拉伸图表
  37. grid: {
  38. top: '10%', // 减小顶部边距,让图表向上扩展
  39. bottom: '10%', // 减小底部边距,让图表向下扩展
  40. right: '0%',
  41. },
  42. xAxis: {
  43. type: 'category',
  44. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
  45. axisLabel: {
  46. color: '#fff'
  47. },
  48. },
  49. yAxis: {
  50. type: 'value',
  51. axisLabel: {
  52. show: true, // 不显示刻度标签
  53. color: '#fff'
  54. },
  55. // 配置 Y 轴网格刻线
  56. splitLine: {
  57. show: false, // 显示网格刻线
  58. lineStyle: {
  59. color: '#44585e' // 设置网格刻线颜色
  60. }
  61. },
  62. axisTick: {
  63. show: false // 不显示刻度线
  64. },
  65. },
  66. series: [
  67. {
  68. name: '开启数量',
  69. type: 'line',
  70. smooth: true,
  71. data: generateRandomData(7, 50),
  72. showSymbol: false,
  73. lineStyle: {
  74. color: 'rgb(49, 143, 247)',
  75. },
  76. areaStyle: {
  77. color: new echarts.graphic.LinearGradient(
  78. 0,
  79. 0,
  80. 0,
  81. 1,
  82. [{
  83. offset: 0,
  84. color: 'rgba(49, 143, 247, 0.6)',
  85. },
  86. {
  87. offset: 0.8,
  88. color: 'rgba(49, 143, 247, 0.2)',
  89. },
  90. ],
  91. false
  92. ),
  93. shadowColor: 'rgba(0, 0, 0, 0.1)',
  94. shadowBlur: 10,
  95. }
  96. },
  97. {
  98. name: '关闭数量',
  99. type: 'line',
  100. smooth: true,
  101. data: generateRandomData(9, 60),
  102. showSymbol: false,
  103. lineStyle: {
  104. color: 'rgb(255,193,7)',
  105. },
  106. areaStyle: {
  107. color: new echarts.graphic.LinearGradient(
  108. 0,
  109. 0,
  110. 0,
  111. 1,
  112. [{
  113. offset: 0,
  114. color: 'rgba(255,193,7, 0.6)',
  115. },
  116. {
  117. offset: 0.8,
  118. color: 'rgba(255,193,7,0.2)',
  119. },
  120. ],
  121. false
  122. ),
  123. shadowColor: 'rgba(0, 0, 0, 0.1)',
  124. shadowBlur: 10,
  125. }
  126. },
  127. {
  128. name: '故障数量',
  129. type: 'line',
  130. smooth: true,
  131. data: generateRandomData(5, 30),
  132. showSymbol: false,
  133. lineStyle: {
  134. color: 'rgb(244,67,54)'
  135. },
  136. areaStyle: {
  137. color: new echarts.graphic.LinearGradient(
  138. 0,
  139. 0,
  140. 0,
  141. 1,
  142. [{
  143. offset: 0,
  144. color: 'rgba(244,67,54,0.6)',
  145. },
  146. {
  147. offset: 0.8,
  148. color: 'rgba(244,67,54,0.2)',
  149. },
  150. ],
  151. false
  152. ),
  153. shadowColor: 'rgba(0, 0, 0, 0.1)',
  154. shadowBlur: 10,
  155. }
  156. }
  157. ]
  158. };
  159. chart.setOption(option);
  160. }
  161. window.addEventListener('resize', handleResize);
  162. });
  163. onUnmounted(() => {
  164. window.removeEventListener('resize', handleResize);
  165. if (chart) {
  166. chart.dispose();
  167. }
  168. });
  169. </script>
  170. <style lang="scss">
  171. ._divider{
  172. height: 1px;
  173. border: 1px dashed #168cdb;
  174. flex: 1;
  175. margin: 0 10px;
  176. }
  177. ._switchAll{
  178. display: flex;
  179. flex-direction: column;
  180. &_mains{
  181. margin:10px 30px;
  182. flex: 1;
  183. display: flex;
  184. &_item{
  185. display: flex;
  186. justify-content: space-between;
  187. align-items: center;
  188. padding: 10px;
  189. &_name{
  190. width: 30px;
  191. height: 30px;
  192. background: url("@/assets/images/content_circle_num.png");
  193. background-size: 100% 100%;
  194. background-position: center;
  195. background-repeat: no-repeat;
  196. // animation: scanning 4s linear infinite;
  197. border: 1px solid red;
  198. }
  199. &_flag{
  200. display: flex;
  201. align-items: center;
  202. gap: 3px;
  203. &_item{
  204. width: 30px;
  205. height: 30px;
  206. border: 3px dashed #168cdb;
  207. box-sizing: border-box;
  208. background:#0e6ead;
  209. color: #fff;
  210. border-radius: 50%;
  211. display: flex;
  212. align-items: center;
  213. justify-content: center;
  214. font-size: 14px;
  215. }
  216. }
  217. }
  218. &_item:hover{
  219. cursor: pointer;
  220. background-image: linear-gradient(to right, #168cdb, transparent);
  221. }
  222. }
  223. }
  224. </style>