weatherChart.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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: require("@/assets/images/home/qi-100.svg"),
  217. },
  218. height: 20,
  219. width: 20,
  220. color: "#fff"
  221. };
  222. });
  223. let weatherImgNightlistStyle = weatherImgNightlist.map((item) => {
  224. let dateUrl = item;
  225. return {
  226. backgroundColor: {
  227. image: dateUrl,
  228. },
  229. height: 20,
  230. width: 20,
  231. };
  232. });
  233. weatherImgDaylistStyle.forEach((i, index) => {
  234. weatherImgDaylistRich[index] = i;
  235. });
  236. weatherImgNightlistStyle.forEach((i, index) => {
  237. weatherImgNightlistRich[index] = i;
  238. });
  239. const myChart = ref(null);
  240. const chartDom = ref(null);
  241. const options = {
  242. grid: {
  243. top: "-100px",
  244. right: "20px",
  245. bottom: '-80px',
  246. left: "-20px",
  247. containLabel: true,
  248. },
  249. xAxis: [
  250. {
  251. type: "category",
  252. boundaryGap: false,
  253. position: "top",
  254. offset: 0,
  255. zlevel: 100,
  256. axisLine: {
  257. show: false,
  258. },
  259. axisTick: {
  260. show: false,
  261. },
  262. splitLine: {
  263. show: false,
  264. },
  265. axisLabel: {
  266. interval: 0,
  267. formatter: ["{a|{value}}"].join("\n"),
  268. rich: {
  269. a: {
  270. color: "#fff",
  271. },
  272. },
  273. },
  274. data: weekday,
  275. },
  276. {
  277. type: "category",
  278. position: "top",
  279. offset: -40,
  280. boundaryGap: false,
  281. zlevel: 100,
  282. axisLine: {
  283. show: false,
  284. },
  285. axisTick: {
  286. show: false,
  287. },
  288. axisLabel: {
  289. interval: 0,
  290. formatter: ["{a|{value}}"].join("\n"),
  291. rich: {
  292. a: {
  293. fontSize: 11,
  294. },
  295. },
  296. },
  297. data: datelist,
  298. axisPointer: {
  299. show: false,
  300. },
  301. },
  302. // {
  303. // type: "category",
  304. // position: "top",
  305. // offset: -40,
  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: "#fff",
  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: -65,
  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. // formatter: `<i class="qi-100-fill"></i>`,
  344. // formatter: function(params) {
  345. // // return `<i class="qi-100-fill"></i>`
  346. // return `<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:#fff"></span>`
  347. // },
  348. rich: weatherImgDaylistRich,
  349. },
  350. data: ["0", "1", "2", "3", "4", "5", "6","7"],
  351. axisPointer: {
  352. show: false,
  353. },
  354. },
  355. {
  356. type: "category",
  357. position: "top",
  358. offset: -85,
  359. boundaryGap: false,
  360. zlevel: 100,
  361. axisLine: {
  362. show: false,
  363. },
  364. axisTick: {
  365. show: false,
  366. },
  367. axisLabel: {
  368. interval: 0,
  369. formatter: ["{a|{value}°}"].join("\n"),
  370. rich: {
  371. a: {
  372. color: "#fff",
  373. },
  374. },
  375. },
  376. data: weatherZgwdlist,
  377. axisPointer: {
  378. show: false,
  379. },
  380. },
  381. {
  382. type: "category",
  383. position: "bottom",
  384. offset: -88,
  385. boundaryGap: false,
  386. zlevel: 100,
  387. axisLine: {
  388. show: false,
  389. },
  390. axisTick: {
  391. show: false,
  392. },
  393. axisLabel: {
  394. interval: 0,
  395. formatter: ["{a|{value}°}"].join("\n"),
  396. rich: {
  397. a: {
  398. color: "#fff",
  399. },
  400. },
  401. },
  402. data: weatherZdwdlist,
  403. axisPointer: {
  404. show: false,
  405. },
  406. },
  407. ],
  408. yAxis: {
  409. show: false,
  410. interval: 15,
  411. type: "value",
  412. axisLabel: {
  413. formatter: "{value}" + "℃",
  414. },
  415. max: maxWD,
  416. min: minWD,
  417. },
  418. series: [
  419. {
  420. name: "最高温度",
  421. type: "line",
  422. data: weatherZgwdlist,
  423. symbol: "circle",
  424. symbolSize: 5,
  425. showSymbol: true,
  426. smooth: true,
  427. itemStyle: {
  428. color: "#FA8258", // 设置圆形的填充色
  429. borderColor: "#ffffff", // 设置边框颜色
  430. borderWidth: 1, // 设置边框宽度
  431. },
  432. lineStyle: {
  433. width: 2, // 设置折线的宽度
  434. color: "#FA8258", // 设置折线的颜色
  435. shadowColor: "#FA8258", // 线的阴影颜色
  436. shadowBlur: 5, // 线的阴影模糊级数
  437. shadowOffsetX: 0, // 线的阴影水平偏移
  438. shadowOffsetY: 5, // 线的阴影垂直偏移
  439. },
  440. silent: false,
  441. },
  442. {
  443. name: "最低温度",
  444. type: "line",
  445. data: weatherZdwdlist,
  446. symbol: "circle",
  447. symbolSize: 5,
  448. showSymbol: true,
  449. smooth: true,
  450. itemStyle: {
  451. color: "#2E9AFE", // 设置圆形的填充色
  452. borderColor: "#ffffff", // 设置边框颜色
  453. borderWidth: 1, // 设置边框宽度
  454. },
  455. lineStyle: {
  456. width: 2, // 设置折线的宽度
  457. color: "#2E9AFE", // 设置折线的颜色
  458. shadowColor: "#2E9AFE", // 线的阴影颜色
  459. shadowBlur: 5, // 线的阴影模糊级数
  460. shadowOffsetX: 0, // 线的阴影水平偏移
  461. shadowOffsetY: 5, // 线的阴影垂直偏移
  462. },
  463. silent: false,
  464. },
  465. ],
  466. };
  467. onMounted(() => {
  468. setTimeout(()=>{
  469. initChart();
  470. },200)
  471. });
  472. // watch(
  473. // () => props.list,
  474. // (newValue, oldValue) => {
  475. // // if(newValue){
  476. // // options.xAxis[0].data = newValue.map(item => item[1] + item[2])
  477. // // options.series[0].data = newValue.map(item => Math.floor(item[3]))
  478. // // }
  479. // myChart.value.setOption(options);
  480. // }
  481. // );
  482. const initChart = () => {
  483. myChart.value = echarts.init(chartDom.value);
  484. myChart.value.setOption(options);
  485. };
  486. </script>
  487. <style lang="scss" scoped>
  488. .chart {
  489. width: 100%;
  490. height: 100%;
  491. }
  492. </style>