weatherChart.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <template>
  2. <div ref="chartDom" class="chart"></div>
  3. </template>
  4. <script setup>
  5. import { onMounted, ref, watch } from "vue";
  6. import * as echarts from "echarts";
  7. // const props = defineProps({
  8. // list: {
  9. // type: Array,
  10. // default: () => [],
  11. // required: true,
  12. // },
  13. // });
  14. let demoData = [
  15. {
  16. sourceof: null,
  17. create_by: null,
  18. update_by: null,
  19. remark: null,
  20. sys_dept_code: null,
  21. createTime: null,
  22. updateTime: null,
  23. rq: "08/28",
  24. weatherZgwd: 30,
  25. weatherZdwd: 18,
  26. weatherTqDay: "晴",
  27. weatherTqNight: "晴",
  28. weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
  29. weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
  30. windDirectDay: "南风",
  31. windDirectNight: "南风",
  32. windPowerDay: "微风",
  33. windPowerNight: "微风",
  34. week: "星期三",
  35. },
  36. {
  37. sourceof: null,
  38. create_by: null,
  39. update_by: null,
  40. remark: null,
  41. sys_dept_code: null,
  42. createTime: null,
  43. updateTime: null,
  44. rq: "08/29",
  45. weatherZgwd: 31,
  46. weatherZdwd: 19,
  47. weatherTqDay: "晴",
  48. weatherTqNight: "晴",
  49. weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
  50. weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
  51. windDirectDay: "南风",
  52. windDirectNight: "南风",
  53. windPowerDay: "微风",
  54. windPowerNight: "微风",
  55. week: "星期四",
  56. },
  57. {
  58. sourceof: null,
  59. create_by: null,
  60. update_by: null,
  61. remark: null,
  62. sys_dept_code: null,
  63. createTime: null,
  64. updateTime: null,
  65. rq: "08/30",
  66. weatherZgwd: 30,
  67. weatherZdwd: 19,
  68. weatherTqDay: "晴",
  69. weatherTqNight: "多云",
  70. weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
  71. weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
  72. windDirectDay: "西南风",
  73. windDirectNight: "北风",
  74. windPowerDay: "微风",
  75. windPowerNight: "微风",
  76. week: "星期五",
  77. },
  78. {
  79. sourceof: null,
  80. create_by: null,
  81. update_by: null,
  82. remark: null,
  83. sys_dept_code: null,
  84. createTime: null,
  85. updateTime: null,
  86. rq: "08/31",
  87. weatherZgwd: 30,
  88. weatherZdwd: 21,
  89. weatherTqDay: "多云",
  90. weatherTqNight: "雷阵雨",
  91. weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
  92. weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
  93. windDirectDay: "北风",
  94. windDirectNight: "南风",
  95. windPowerDay: "3~4级",
  96. windPowerNight: "3~4级",
  97. week: "星期六",
  98. },
  99. {
  100. sourceof: null,
  101. create_by: null,
  102. update_by: null,
  103. remark: null,
  104. sys_dept_code: null,
  105. createTime: null,
  106. updateTime: null,
  107. rq: "09/01",
  108. weatherZgwd: 25,
  109. weatherZdwd: 16,
  110. weatherTqDay: "雷阵雨",
  111. weatherTqNight: "多云",
  112. weatherImgDay: "https://d.scggqx.com/forecast/img/多云.png",
  113. weatherImgNight: "https://d.scggqx.com/forecast/img/多云.png",
  114. windDirectDay: "北风",
  115. windDirectNight: "北风",
  116. windPowerDay: "3~4级",
  117. windPowerNight: "3~4级",
  118. week: "星期日",
  119. },
  120. {
  121. sourceof: null,
  122. create_by: null,
  123. update_by: null,
  124. remark: null,
  125. sys_dept_code: null,
  126. createTime: null,
  127. updateTime: null,
  128. rq: "09/02",
  129. weatherZgwd: 26,
  130. weatherZdwd: 15,
  131. weatherTqDay: "晴",
  132. weatherTqNight: "晴",
  133. weatherImgDay: "https://d.scggqx.com/forecast/img/阴.png",
  134. weatherImgNight: "https://d.scggqx.com/forecast/img/阴.png",
  135. windDirectDay: "北风",
  136. windDirectNight: "北风",
  137. windPowerDay: "3~4级",
  138. windPowerNight: "微风",
  139. week: "星期一",
  140. },
  141. {
  142. sourceof: null,
  143. create_by: null,
  144. update_by: null,
  145. remark: null,
  146. sys_dept_code: null,
  147. createTime: null,
  148. updateTime: null,
  149. rq: "09/03",
  150. weatherZgwd: 27,
  151. weatherZdwd: 18,
  152. weatherTqDay: "多云",
  153. weatherTqNight: "阴",
  154. weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
  155. weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
  156. windDirectDay: "无持续风向",
  157. windDirectNight: "无持续风向",
  158. windPowerDay: "微风",
  159. windPowerNight: "微风",
  160. week: "星期二",
  161. },
  162. {
  163. sourceof: null,
  164. create_by: null,
  165. update_by: null,
  166. remark: null,
  167. sys_dept_code: null,
  168. createTime: null,
  169. updateTime: null,
  170. rq: "09/04",
  171. weatherZgwd: 27,
  172. weatherZdwd: 18,
  173. weatherTqDay: "多云",
  174. weatherTqNight: "阴",
  175. weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
  176. weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
  177. windDirectDay: "无持续风向",
  178. windDirectNight: "无持续风向",
  179. windPowerDay: "微风",
  180. windPowerNight: "微风",
  181. week: "星期二",
  182. },
  183. ];
  184. let weekday = [];
  185. let datelist = [];
  186. let weatherDaylist = [];
  187. let weatherNightlist = [];
  188. let weatherImgDaylist = [];
  189. let weatherImgNightlist = [];
  190. let windDirectlist = [];
  191. let windPowerlist = [];
  192. let weatherZgwdlist = [];
  193. let weatherZdwdlist = [];
  194. let weatherImgDaylistRich = {};
  195. let weatherImgNightlistRich = {};
  196. let maxWD = 30;
  197. let minWD = 0;
  198. demoData.forEach((item) => {
  199. weekday.push(item.week);
  200. datelist.push(item.rq);
  201. weatherDaylist.push(item.weatherTqDay);
  202. weatherNightlist.push(item.weatherTqNight);
  203. weatherImgDaylist.push(item.weatherImgDay);
  204. weatherImgNightlist.push(item.weatherImgNight);
  205. windDirectlist.push(item.windDirectDay);
  206. windPowerlist.push(item.windPowerDay);
  207. weatherZgwdlist.push(item.weatherZgwd);
  208. weatherZdwdlist.push(item.weatherZdwd);
  209. });
  210. maxWD = Math.max(...weatherZgwdlist) + 30;
  211. minWD = Math.min(...weatherZdwdlist) - 30;
  212. let weatherImgDaylistStyle = weatherImgDaylist.map((item) => {
  213. let dateUrl = item;
  214. return {
  215. backgroundColor: {
  216. image: dateUrl,
  217. },
  218. height: 20,
  219. width: 20,
  220. };
  221. });
  222. let weatherImgNightlistStyle = weatherImgNightlist.map((item) => {
  223. let dateUrl = item;
  224. return {
  225. backgroundColor: {
  226. image: dateUrl,
  227. },
  228. height: 20,
  229. width: 20,
  230. };
  231. });
  232. weatherImgDaylistStyle.forEach((i, index) => {
  233. weatherImgDaylistRich[index] = i;
  234. });
  235. weatherImgNightlistStyle.forEach((i, index) => {
  236. weatherImgNightlistRich[index] = i;
  237. });
  238. const myChart = ref(null);
  239. const chartDom = ref(null);
  240. const options = {
  241. grid: {
  242. top: "-100px",
  243. right: "20px",
  244. bottom: '-55px',
  245. left: "-20px",
  246. containLabel: true,
  247. },
  248. xAxis: [
  249. {
  250. type: "category",
  251. boundaryGap: false,
  252. position: "top",
  253. offset: 0,
  254. zlevel: 100,
  255. axisLine: {
  256. show: false,
  257. },
  258. axisTick: {
  259. show: false,
  260. },
  261. splitLine: {
  262. show: false,
  263. },
  264. axisLabel: {
  265. interval: 0,
  266. formatter: ["{a|{value}}"].join("\n"),
  267. rich: {
  268. a: {
  269. color: "#000",
  270. },
  271. },
  272. },
  273. data: weekday,
  274. },
  275. {
  276. type: "category",
  277. position: "top",
  278. offset: -15,
  279. boundaryGap: false,
  280. zlevel: 100,
  281. axisLine: {
  282. show: false,
  283. },
  284. axisTick: {
  285. show: false,
  286. },
  287. axisLabel: {
  288. interval: 0,
  289. formatter: ["{a|{value}}"].join("\n"),
  290. rich: {
  291. a: {
  292. color: "#999999",
  293. fontSize: 10,
  294. },
  295. },
  296. },
  297. data: datelist,
  298. axisPointer: {
  299. show: false,
  300. },
  301. },
  302. {
  303. type: "category",
  304. position: "top",
  305. offset: -35,
  306. boundaryGap: false,
  307. zlevel: 100,
  308. axisLine: {
  309. show: false,
  310. },
  311. axisTick: {
  312. show: false,
  313. },
  314. axisLabel: {
  315. interval: 0,
  316. formatter: ["{a|{value}}"].join("\n"),
  317. rich: {
  318. a: {
  319. color: "#000",
  320. },
  321. },
  322. },
  323. data: weatherDaylist,
  324. axisPointer: {
  325. show: false,
  326. },
  327. },
  328. {
  329. type: "category",
  330. boundaryGap: false,
  331. position: "top",
  332. offset: -60,
  333. zlevel: 100,
  334. axisLine: {
  335. show: false,
  336. },
  337. axisTick: {
  338. show: false,
  339. },
  340. axisLabel: {
  341. interval: 0,
  342. formatter: ["{{value}|}"].join("\n"),
  343. rich: weatherImgDaylistRich,
  344. },
  345. data: ["0", "1", "2", "3", "4", "5", "6","7"],
  346. axisPointer: {
  347. show: false,
  348. },
  349. },
  350. {
  351. type: "category",
  352. position: "top",
  353. offset: -80,
  354. boundaryGap: false,
  355. zlevel: 100,
  356. axisLine: {
  357. show: false,
  358. },
  359. axisTick: {
  360. show: false,
  361. },
  362. axisLabel: {
  363. interval: 0,
  364. formatter: ["{a|{value}°}"].join("\n"),
  365. rich: {
  366. a: {
  367. color: "#000",
  368. },
  369. },
  370. },
  371. data: weatherZgwdlist,
  372. axisPointer: {
  373. show: false,
  374. },
  375. },
  376. {
  377. type: "category",
  378. position: "top",
  379. offset: -160,
  380. boundaryGap: false,
  381. zlevel: 100,
  382. axisLine: {
  383. show: false,
  384. },
  385. axisTick: {
  386. show: false,
  387. },
  388. axisLabel: {
  389. interval: 0,
  390. formatter: ["{a|{value}°}"].join("\n"),
  391. rich: {
  392. a: {
  393. color: "#000",
  394. },
  395. },
  396. },
  397. data: weatherZgwdlist,
  398. axisPointer: {
  399. show: false,
  400. },
  401. },
  402. ],
  403. yAxis: {
  404. show: false,
  405. interval: 15,
  406. type: "value",
  407. axisLabel: {
  408. formatter: "{value}" + "℃",
  409. },
  410. max: maxWD,
  411. min: minWD,
  412. },
  413. series: [
  414. {
  415. name: "最高温度",
  416. type: "line",
  417. data: weatherZgwdlist,
  418. symbol: "circle",
  419. symbolSize: 3,
  420. showSymbol: true,
  421. smooth: true,
  422. itemStyle: {
  423. color: "#FA8258", // 设置圆形的填充色
  424. borderColor: "#FA8258", // 设置边框颜色
  425. borderWidth: 3, // 设置边框宽度
  426. },
  427. lineStyle: {
  428. width: 2, // 设置折线的宽度
  429. color: "#FA8258", // 设置折线的颜色
  430. shadowColor: "#FA8258", // 线的阴影颜色
  431. shadowBlur: 5, // 线的阴影模糊级数
  432. shadowOffsetX: 0, // 线的阴影水平偏移
  433. shadowOffsetY: 5, // 线的阴影垂直偏移
  434. },
  435. silent: false,
  436. },
  437. {
  438. name: "最低温度",
  439. type: "line",
  440. data: weatherZdwdlist,
  441. symbol: "circle",
  442. symbolSize: 3,
  443. showSymbol: true,
  444. smooth: true,
  445. itemStyle: {
  446. color: "#2E9AFE", // 设置圆形的填充色
  447. borderColor: "#2E9AFE", // 设置边框颜色
  448. borderWidth: 3, // 设置边框宽度
  449. },
  450. lineStyle: {
  451. width: 2, // 设置折线的宽度
  452. color: "#2E9AFE", // 设置折线的颜色
  453. shadowColor: "#2E9AFE", // 线的阴影颜色
  454. shadowBlur: 5, // 线的阴影模糊级数
  455. shadowOffsetX: 0, // 线的阴影水平偏移
  456. shadowOffsetY: 5, // 线的阴影垂直偏移
  457. },
  458. silent: false,
  459. },
  460. ],
  461. };
  462. onMounted(() => {
  463. setTimeout(()=>{
  464. initChart();
  465. },200)
  466. });
  467. // watch(
  468. // () => props.list,
  469. // (newValue, oldValue) => {
  470. // // if(newValue){
  471. // // options.xAxis[0].data = newValue.map(item => item[1] + item[2])
  472. // // options.series[0].data = newValue.map(item => Math.floor(item[3]))
  473. // // }
  474. // myChart.value.setOption(options);
  475. // }
  476. // );
  477. const initChart = () => {
  478. myChart.value = echarts.init(chartDom.value);
  479. myChart.value.setOption(options);
  480. };
  481. </script>
  482. <style lang="scss" scoped>
  483. .chart {
  484. width: 100%;
  485. height: 100%;
  486. }
  487. </style>