Line.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <script setup lang="ts">
  2. import { useIntervalFn } from "@vueuse/core";
  3. import { ref, computed, watch, type Ref } from "vue";
  4. import { useAppStoreHook } from "@/store/modules/app";
  5. import {
  6. delay,
  7. useDark,
  8. useECharts,
  9. type EchartOptions
  10. } from "@pureadmin/utils";
  11. const { isDark } = useDark();
  12. const theme: EchartOptions["theme"] = computed(() => {
  13. return isDark.value ? "dark" : "default";
  14. });
  15. const lineChartRef = ref<HTMLDivElement | null>(null);
  16. const { setOptions, getInstance, resize } = useECharts(
  17. lineChartRef as Ref<HTMLDivElement>,
  18. { theme }
  19. );
  20. const xData = (() => {
  21. const data: any[] = [];
  22. for (let i = 1; i < 31; i++) {
  23. data.push(`${i}日`);
  24. }
  25. return data;
  26. })();
  27. setOptions(
  28. {
  29. tooltip: {
  30. trigger: "axis",
  31. axisPointer: {
  32. type: "shadow"
  33. }
  34. },
  35. grid: {
  36. bottom: "20px",
  37. right: "10px"
  38. },
  39. legend: {
  40. //@ts-expect-error
  41. right: true,
  42. data: ["fork", "star"]
  43. },
  44. calculable: true,
  45. xAxis: [
  46. {
  47. triggerEvent: true,
  48. type: "category",
  49. splitLine: {
  50. show: false
  51. },
  52. axisTick: {
  53. show: false
  54. },
  55. data: xData
  56. }
  57. ],
  58. yAxis: [
  59. {
  60. triggerEvent: true,
  61. type: "value",
  62. splitLine: {
  63. show: false
  64. },
  65. axisLine: {
  66. show: true
  67. }
  68. }
  69. ],
  70. dataZoom: [
  71. {
  72. type: "slider",
  73. show: false,
  74. realtime: true,
  75. startValue: 0,
  76. endValue: 24
  77. }
  78. ],
  79. series: [
  80. {
  81. name: "fork",
  82. type: "line",
  83. symbolSize: 10,
  84. symbol: "circle",
  85. color: "#f56c6c",
  86. markPoint: {
  87. label: {
  88. color: "#fff"
  89. },
  90. data: [
  91. {
  92. type: "max",
  93. name: "最大值"
  94. },
  95. {
  96. type: "min",
  97. name: "最小值"
  98. }
  99. ]
  100. },
  101. data: [
  102. 509, 917, 2455, 2610, 2719, 3033, 3044, 3085, 2708, 2809, 2117, 2000,
  103. 1455, 1210, 719, 733, 944, 2285, 2208, 3372, 3936, 3693, 2962, 2810,
  104. 3519, 2455, 2610, 2719, 2484, 2078
  105. ]
  106. },
  107. {
  108. name: "star",
  109. type: "line",
  110. symbolSize: 10,
  111. symbol: "circle",
  112. color: "#53a7ff",
  113. markPoint: {
  114. label: {
  115. color: "#fff"
  116. },
  117. data: [
  118. {
  119. type: "max",
  120. name: "最大值"
  121. },
  122. {
  123. type: "min",
  124. name: "最小值"
  125. }
  126. ]
  127. },
  128. data: [
  129. 2136, 3693, 2962, 3810, 3519, 3484, 3915, 3823, 3455, 4310, 4019,
  130. 3433, 3544, 3885, 4208, 3372, 3484, 3915, 3748, 3675, 4009, 4433,
  131. 3544, 3285, 4208, 3372, 3484, 3915, 3823, 4265, 4298
  132. ]
  133. }
  134. ],
  135. addTooltip: true
  136. },
  137. {
  138. name: "click",
  139. callback: params => {
  140. console.log("click", params);
  141. }
  142. },
  143. {
  144. name: "contextmenu",
  145. callback: params => {
  146. console.log("contextmenu", params);
  147. }
  148. },
  149. // 点击空白处
  150. {
  151. type: "zrender",
  152. name: "click",
  153. callback: params => {
  154. console.log("点击空白处", params);
  155. }
  156. }
  157. );
  158. let a = 1;
  159. useIntervalFn(() => {
  160. if (a == xData.length - 24) {
  161. a = 0;
  162. }
  163. getInstance()!.dispatchAction({
  164. type: "dataZoom",
  165. startValue: a,
  166. endValue: a + 24
  167. });
  168. a++;
  169. }, 2000);
  170. watch(
  171. () => useAppStoreHook().getSidebarStatus,
  172. () => {
  173. delay(600).then(() => resize());
  174. }
  175. );
  176. </script>
  177. <template>
  178. <div ref="lineChartRef" style="width: 100%; height: 35vh" />
  179. </template>