You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

353 lines
8.9 KiB

4 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
  1. <template>
  2. <!-- <div ref="qxnlzhqEchartsRef" id="qxnlzhqEcharts"></div> -->
  3. <div class="qxjmqbox">
  4. <div ref="KlineCanvs" id="qxjmqEcharts" class="qxjmqbox"></div>
  5. </div>
  6. </template>
  7. <script setup>
  8. import { ref, onMounted, onBeforeUnmount, toRef } from "vue";
  9. import * as echarts from "echarts";
  10. import { color } from "echarts/lib/export";
  11. defineExpose({ initQXNLZHEcharts });
  12. const KlineCanvs = ref(null);
  13. let KlineCanvsChart = null;
  14. const heatmapData = ref([]); // 存储热力图数据
  15. // 假数据
  16. const rawData2 = ref([]);
  17. const lineData3 = ref([]);
  18. function initQXNLZHEcharts(kline, qxnlzhqData) {
  19. qxnlzhqData[9][9] = 1;
  20. qxnlzhqData[2][9] = 1;
  21. rawData2.value = qxnlzhqData;
  22. // 处理热力图数据
  23. const processedHeatmap = [];
  24. rawData2.value.forEach((item, dateIndex) => {
  25. const [date, d1, d2, d3, d4, d5, d6, d7, d8, d9] = item;
  26. processedHeatmap.push([
  27. dateIndex,
  28. 0,
  29. d4,
  30. d8 == 1 ? "green" : "transparent",
  31. ]); // 数据1
  32. processedHeatmap.push([
  33. dateIndex,
  34. 1,
  35. d3,
  36. d7 == 1 ? "purple" : "transparent",
  37. ]); // 数据2
  38. processedHeatmap.push([dateIndex, 2, d2, d6 == 1 ? "red" : "transparent"]); // 数据3
  39. processedHeatmap.push([
  40. dateIndex,
  41. 3,
  42. d1,
  43. d5 == 1 ? "yellow" : "transparent",
  44. ]); // 数据4
  45. });
  46. heatmapData.value = processedHeatmap;
  47. // 处理折线图数据
  48. lineData3.value = rawData2.value.map((item) => item[9]);
  49. console.log("热力图数据:", heatmapData.value);
  50. console.log("折线图数据:", lineData3.value);
  51. const data = kline;
  52. // 切割数据方法
  53. const spliteDate = (a) => {
  54. const categoryData = [];
  55. let value = [];
  56. for (let i = 0; i < a.length; i++) {
  57. categoryData.push(a[i].splice(0, 1)[0]);
  58. value.push(a[i]);
  59. }
  60. return { categoryData, value };
  61. };
  62. const dealData = spliteDate(data);
  63. // 给配置项
  64. const KlineOption = {
  65. tooltip: {
  66. trigger: "item", // 触发类型 坐标轴触发
  67. // axisPointer: {
  68. // type: "cross", // 十字准星效果
  69. // crossStyle: {
  70. // color: "#999"
  71. // }
  72. // }
  73. },
  74. //控制坐标轴
  75. grid: [
  76. { top: "5%", height: "40%" },
  77. { top: "45%", height: "35%" },
  78. { top: "80%", height: "2%" },
  79. ],
  80. visualMap: [
  81. {
  82. show: false, // 不显示控制条
  83. seriesIndex: 1, // 作用于热力图的系列
  84. min: 0,
  85. max: 2000, // 根据您的数据范围调整
  86. calculable: true,
  87. orient: "horizontal",
  88. left: "center",
  89. bottom: "15%",
  90. inRange: {
  91. color: ["transparent"],
  92. },
  93. },
  94. ],
  95. // 横坐标内容
  96. xAxis: [
  97. {
  98. type: "category",
  99. gridIndex: 0,
  100. data: dealData.categoryData,
  101. axisPointer: {
  102. show: true,
  103. type: "shadow",
  104. },
  105. axisTick: { show: false }, // 隐藏刻度线
  106. axisLabel: { show: false, rotate: 45 }, // 隐藏刻度标签
  107. axisLine: {
  108. show: true,
  109. lineStyle: {
  110. color: "grey",
  111. },
  112. },
  113. },
  114. {
  115. type: "category",
  116. gridIndex: 1,
  117. data: dealData.categoryData,
  118. axisTick: { show: false }, // 隐藏刻度线
  119. axisLabel: { show: false, rotate: 45 }, // 隐藏刻度标签
  120. splitLine: {
  121. show: true,
  122. lineStyle: {
  123. color: "white",
  124. // 间隔线类型实线
  125. type: "solid",
  126. },
  127. interval: 0,
  128. },
  129. },
  130. {
  131. type: "category",
  132. gridIndex: 2,
  133. data: dealData.categoryData,
  134. axisLine: { lineStyle: { color: "#8392A5" } },
  135. },
  136. ],
  137. yAxis: [
  138. {
  139. scale: true,
  140. axisLabel: {
  141. formatter: function (value) {
  142. return value;
  143. },
  144. },
  145. axisLine: {
  146. show: true,
  147. lineStyle: { color: "#8392A5" },
  148. },
  149. splitLine: {
  150. show: false,
  151. },
  152. axisPointer: {
  153. show: true,
  154. label: {
  155. show: true,
  156. },
  157. type: "line",
  158. },
  159. },
  160. {
  161. gridIndex: 1,
  162. type: "category",
  163. data: [0, 1, 2, 3], // 倒序显示
  164. axisLine: { lineStyle: { color: "#8392A5" } },
  165. axisLabel: {
  166. show: true, // 显示刻度标签
  167. color: "#fff", // 白色文字
  168. backgroundColor: "transparent",
  169. fontSize: 12,
  170. margin: 8,
  171. },
  172. axisTick: { show: false }, // 隐藏刻度线
  173. splitLine: {
  174. show: true,
  175. lineStyle: {
  176. color: "#8392A5",
  177. width: 1,
  178. type: "solid",
  179. },
  180. interval: 0, // 强制显示间隔
  181. },
  182. },
  183. {
  184. gridIndex: 2,
  185. type: "value",
  186. axisLine: {
  187. show: true,
  188. lineStyle: { color: "#8392A5" },
  189. },
  190. splitLine: {
  191. show: !1,
  192. },
  193. axisTick: { show: false }, // 隐藏刻度线
  194. axisLabel: { show: false }, // 隐藏刻度标签
  195. },
  196. ],
  197. // 下拉条
  198. dataZoom: [
  199. {
  200. textStyle: {
  201. color: "white", // 字体颜色
  202. },
  203. handleIcon:
  204. "M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z",
  205. handleSize: "80%",
  206. dataBackground: {
  207. areaStyle: {
  208. color: "#8392A5",
  209. },
  210. lineStyle: {
  211. opacity: 0.8,
  212. color: "#8392A5",
  213. },
  214. },
  215. xAxisIndex: [0, 1, 2],
  216. handleStyle: {
  217. color: "#fff",
  218. shadowBlur: 3,
  219. shadowColor: "rgba(0, 0, 0, 0.6)",
  220. shadowOffsetX: 2,
  221. shadowOffsetY: 2,
  222. },
  223. bottom: "5%", // 下移数据缩放滑块
  224. },
  225. {
  226. show: !1,
  227. type: "slider",
  228. },
  229. {
  230. type: "inside",
  231. },
  232. ],
  233. series: [
  234. {
  235. type: "candlestick",
  236. name: "\u65e5K",
  237. // 数据
  238. data: dealData.value,
  239. itemStyle: {
  240. normal: {
  241. color0: "red", // 阴线颜色
  242. color: "#0CF49B", // 阳线颜色
  243. borderColor0: "#FD1050", // 阴线边框颜色
  244. borderColor: "#0CF49B", // 阳线边框颜色
  245. },
  246. },
  247. },
  248. // 副图热力矩阵
  249. {
  250. name: "热力矩阵",
  251. type: "heatmap",
  252. gridIndex: 1,
  253. xAxisIndex: 1,
  254. yAxisIndex: 1,
  255. data: processedHeatmap,
  256. coordinateSystem: "cartesian2d",
  257. // tooltip: {
  258. // // 覆盖全局 tooltip 配置
  259. // formatter: function (params) {
  260. // const date = params.axisValue;
  261. // return `${date}:${params.data[2]}`; // 直接取数据中的第3个元素(数值)
  262. // }
  263. // },
  264. label: {
  265. normal: {
  266. show: true,
  267. color: "#fff", // 文本颜色
  268. formatter: function (params) {
  269. const value = params.value[2]; // 数值
  270. const colorType = params.value[3]; // 颜色类型
  271. // 使用 rich 富文本格式
  272. return `{${colorType}|${value}}`;
  273. },
  274. rich: {
  275. green: { color: "#27ae60", fontWeight: "bold" },
  276. purple: { color: "#8e44ad", fontWeight: "bold" },
  277. red: { color: "#FF0000", fontWeight: "bold" },
  278. yellow: { color: "#FFFF00", fontWeight: "bold" },
  279. normal: { color: "#fff" },
  280. },
  281. },
  282. },
  283. itemStyle: {
  284. normal: {
  285. color: "transparent",
  286. borderWidth: 2,
  287. },
  288. },
  289. emphasis: {
  290. itemStyle: {
  291. shadowBlur: 10,
  292. shadowColor: "rgba(0, 0, 0, 0.5)",
  293. },
  294. },
  295. },
  296. {
  297. name: "凸起",
  298. type: "line",
  299. xAxisIndex: 2,
  300. yAxisIndex: 2,
  301. data: lineData3.value,
  302. color: "black",
  303. lineStyle: {
  304. normal: {
  305. color: "red",
  306. },
  307. },
  308. symbol: "none",
  309. emphasis: {
  310. showSymbol: true,
  311. },
  312. },
  313. ],
  314. };
  315. // 创造echarts图
  316. KlineCanvsChart = echarts.init(KlineCanvs.value);
  317. KlineCanvsChart.setOption(KlineOption);
  318. // 窗口大小变化时重置图表大小
  319. window.addEventListener("resize", () => {
  320. KlineCanvsChart.resize();
  321. });
  322. }
  323. const windowHeight = ref(window.innerHeight);
  324. const updateHeight = () => {
  325. windowHeight.value = window.innerHeight; // 更新响应式变量
  326. };
  327. onMounted(() => {
  328. window.addEventListener("resize", updateHeight); // 监听窗口变化
  329. });
  330. onBeforeUnmount(() => {
  331. // 组件卸载时销毁图表
  332. if (KlineCanvsChart) {
  333. KlineCanvsChart.dispose();
  334. }
  335. });
  336. </script>
  337. <style scoped>
  338. /* .qxjmqbox {
  339. background-color: black;
  340. } */
  341. #qxjmqEcharts {
  342. width: 90%;
  343. height: 500px;
  344. }
  345. </style>