123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503 |
- <template>
- <div ref="chartDom" class="chart"></div>
- </template>
- <script setup>
- import { onMounted, ref, watch } from "vue";
- import * as echarts from "echarts";
- // const props = defineProps({
- // list: {
- // type: Array,
- // default: () => [],
- // required: true,
- // },
- // });
- let demoData = [
- {
- sourceof: null,
- create_by: null,
- update_by: null,
- remark: null,
- sys_dept_code: null,
- createTime: null,
- updateTime: null,
- rq: "08/28",
- weatherZgwd: 30,
- weatherZdwd: 18,
- weatherTqDay: "晴",
- weatherTqNight: "晴",
- weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
- weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
- windDirectDay: "南风",
- windDirectNight: "南风",
- windPowerDay: "微风",
- windPowerNight: "微风",
- week: "星期三",
- },
- {
- sourceof: null,
- create_by: null,
- update_by: null,
- remark: null,
- sys_dept_code: null,
- createTime: null,
- updateTime: null,
- rq: "08/29",
- weatherZgwd: 31,
- weatherZdwd: 19,
- weatherTqDay: "晴",
- weatherTqNight: "晴",
- weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
- weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
- windDirectDay: "南风",
- windDirectNight: "南风",
- windPowerDay: "微风",
- windPowerNight: "微风",
- week: "星期四",
- },
- {
- sourceof: null,
- create_by: null,
- update_by: null,
- remark: null,
- sys_dept_code: null,
- createTime: null,
- updateTime: null,
- rq: "08/30",
- weatherZgwd: 30,
- weatherZdwd: 19,
- weatherTqDay: "晴",
- weatherTqNight: "多云",
- weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
- weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
- windDirectDay: "西南风",
- windDirectNight: "北风",
- windPowerDay: "微风",
- windPowerNight: "微风",
- week: "星期五",
- },
- {
- sourceof: null,
- create_by: null,
- update_by: null,
- remark: null,
- sys_dept_code: null,
- createTime: null,
- updateTime: null,
- rq: "08/31",
- weatherZgwd: 30,
- weatherZdwd: 21,
- weatherTqDay: "多云",
- weatherTqNight: "雷阵雨",
- weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
- weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
- windDirectDay: "北风",
- windDirectNight: "南风",
- windPowerDay: "3~4级",
- windPowerNight: "3~4级",
- week: "星期六",
- },
- {
- sourceof: null,
- create_by: null,
- update_by: null,
- remark: null,
- sys_dept_code: null,
- createTime: null,
- updateTime: null,
- rq: "09/01",
- weatherZgwd: 25,
- weatherZdwd: 16,
- weatherTqDay: "雷阵雨",
- weatherTqNight: "多云",
- weatherImgDay: "https://d.scggqx.com/forecast/img/多云.png",
- weatherImgNight: "https://d.scggqx.com/forecast/img/多云.png",
- windDirectDay: "北风",
- windDirectNight: "北风",
- windPowerDay: "3~4级",
- windPowerNight: "3~4级",
- week: "星期日",
- },
- {
- sourceof: null,
- create_by: null,
- update_by: null,
- remark: null,
- sys_dept_code: null,
- createTime: null,
- updateTime: null,
- rq: "09/02",
- weatherZgwd: 26,
- weatherZdwd: 15,
- weatherTqDay: "晴",
- weatherTqNight: "晴",
- weatherImgDay: "https://d.scggqx.com/forecast/img/阴.png",
- weatherImgNight: "https://d.scggqx.com/forecast/img/阴.png",
- windDirectDay: "北风",
- windDirectNight: "北风",
- windPowerDay: "3~4级",
- windPowerNight: "微风",
- week: "星期一",
- },
- {
- sourceof: null,
- create_by: null,
- update_by: null,
- remark: null,
- sys_dept_code: null,
- createTime: null,
- updateTime: null,
- rq: "09/03",
- weatherZgwd: 27,
- weatherZdwd: 18,
- weatherTqDay: "多云",
- weatherTqNight: "阴",
- weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
- weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
- windDirectDay: "无持续风向",
- windDirectNight: "无持续风向",
- windPowerDay: "微风",
- windPowerNight: "微风",
- week: "星期二",
- },
- {
- sourceof: null,
- create_by: null,
- update_by: null,
- remark: null,
- sys_dept_code: null,
- createTime: null,
- updateTime: null,
- rq: "09/04",
- weatherZgwd: 27,
- weatherZdwd: 18,
- weatherTqDay: "多云",
- weatherTqNight: "阴",
- weatherImgDay: "https://d.scggqx.com/forecast/img/小雨.png",
- weatherImgNight: "https://d.scggqx.com/forecast/img/小雨.png",
- windDirectDay: "无持续风向",
- windDirectNight: "无持续风向",
- windPowerDay: "微风",
- windPowerNight: "微风",
- week: "星期二",
- },
- ];
- let weekday = [];
- let datelist = [];
- let weatherDaylist = [];
- let weatherNightlist = [];
- let weatherImgDaylist = [];
- let weatherImgNightlist = [];
- let windDirectlist = [];
- let windPowerlist = [];
- let weatherZgwdlist = [];
- let weatherZdwdlist = [];
- let weatherImgDaylistRich = {};
- let weatherImgNightlistRich = {};
- let maxWD = 30;
- let minWD = 0;
- demoData.forEach((item) => {
- weekday.push(item.week);
- datelist.push(item.rq);
- weatherDaylist.push(item.weatherTqDay);
- weatherNightlist.push(item.weatherTqNight);
- weatherImgDaylist.push(item.weatherImgDay);
- weatherImgNightlist.push(item.weatherImgNight);
- windDirectlist.push(item.windDirectDay);
- windPowerlist.push(item.windPowerDay);
- weatherZgwdlist.push(item.weatherZgwd);
- weatherZdwdlist.push(item.weatherZdwd);
- });
- maxWD = Math.max(...weatherZgwdlist) + 30;
- minWD = Math.min(...weatherZdwdlist) - 30;
- let weatherImgDaylistStyle = weatherImgDaylist.map((item) => {
- let dateUrl = item;
- return {
- backgroundColor: {
- image: dateUrl,
- },
- height: 20,
- width: 20,
- };
- });
- let weatherImgNightlistStyle = weatherImgNightlist.map((item) => {
- let dateUrl = item;
- return {
- backgroundColor: {
- image: dateUrl,
- },
- height: 20,
- width: 20,
- };
- });
- weatherImgDaylistStyle.forEach((i, index) => {
- weatherImgDaylistRich[index] = i;
- });
- weatherImgNightlistStyle.forEach((i, index) => {
- weatherImgNightlistRich[index] = i;
- });
- const myChart = ref(null);
- const chartDom = ref(null);
- const options = {
- grid: {
- top: "-100px",
- right: "20px",
- bottom: '-55px',
- left: "-20px",
- containLabel: true,
- },
- xAxis: [
- {
- type: "category",
- boundaryGap: false,
- position: "top",
- offset: 0,
- zlevel: 100,
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- axisLabel: {
- interval: 0,
- formatter: ["{a|{value}}"].join("\n"),
- rich: {
- a: {
- color: "#000",
- },
- },
- },
- data: weekday,
- },
- {
- type: "category",
- position: "top",
- offset: -15,
- boundaryGap: false,
- zlevel: 100,
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- axisLabel: {
- interval: 0,
- formatter: ["{a|{value}}"].join("\n"),
- rich: {
- a: {
- color: "#999999",
- fontSize: 10,
- },
- },
- },
- data: datelist,
- axisPointer: {
- show: false,
- },
- },
- {
- type: "category",
- position: "top",
- offset: -35,
- boundaryGap: false,
- zlevel: 100,
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- axisLabel: {
- interval: 0,
- formatter: ["{a|{value}}"].join("\n"),
- rich: {
- a: {
- color: "#000",
- },
- },
- },
- data: weatherDaylist,
- axisPointer: {
- show: false,
- },
- },
- {
- type: "category",
- boundaryGap: false,
- position: "top",
- offset: -60,
- zlevel: 100,
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- axisLabel: {
- interval: 0,
- formatter: ["{{value}|}"].join("\n"),
- rich: weatherImgDaylistRich,
- },
- data: ["0", "1", "2", "3", "4", "5", "6","7"],
- axisPointer: {
- show: false,
- },
- },
- {
- type: "category",
- position: "top",
- offset: -80,
- boundaryGap: false,
- zlevel: 100,
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- axisLabel: {
- interval: 0,
- formatter: ["{a|{value}°}"].join("\n"),
- rich: {
- a: {
- color: "#000",
- },
- },
- },
- data: weatherZgwdlist,
- axisPointer: {
- show: false,
- },
- },
- {
- type: "category",
- position: "top",
- offset: -160,
- boundaryGap: false,
- zlevel: 100,
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- axisLabel: {
- interval: 0,
- formatter: ["{a|{value}°}"].join("\n"),
- rich: {
- a: {
- color: "#000",
- },
- },
- },
- data: weatherZgwdlist,
- axisPointer: {
- show: false,
- },
- },
- ],
- yAxis: {
- show: false,
- interval: 15,
- type: "value",
- axisLabel: {
- formatter: "{value}" + "℃",
- },
- max: maxWD,
- min: minWD,
- },
- series: [
- {
- name: "最高温度",
- type: "line",
- data: weatherZgwdlist,
- symbol: "circle",
- symbolSize: 3,
- showSymbol: true,
- smooth: true,
- itemStyle: {
- color: "#FA8258", // 设置圆形的填充色
- borderColor: "#FA8258", // 设置边框颜色
- borderWidth: 3, // 设置边框宽度
- },
- lineStyle: {
- width: 2, // 设置折线的宽度
- color: "#FA8258", // 设置折线的颜色
- shadowColor: "#FA8258", // 线的阴影颜色
- shadowBlur: 5, // 线的阴影模糊级数
- shadowOffsetX: 0, // 线的阴影水平偏移
- shadowOffsetY: 5, // 线的阴影垂直偏移
- },
- silent: false,
- },
- {
- name: "最低温度",
- type: "line",
- data: weatherZdwdlist,
- symbol: "circle",
- symbolSize: 3,
- showSymbol: true,
- smooth: true,
- itemStyle: {
- color: "#2E9AFE", // 设置圆形的填充色
- borderColor: "#2E9AFE", // 设置边框颜色
- borderWidth: 3, // 设置边框宽度
- },
- lineStyle: {
- width: 2, // 设置折线的宽度
- color: "#2E9AFE", // 设置折线的颜色
- shadowColor: "#2E9AFE", // 线的阴影颜色
- shadowBlur: 5, // 线的阴影模糊级数
- shadowOffsetX: 0, // 线的阴影水平偏移
- shadowOffsetY: 5, // 线的阴影垂直偏移
- },
- silent: false,
- },
- ],
- };
- onMounted(() => {
- setTimeout(()=>{
- initChart();
- },200)
- });
- // watch(
- // () => props.list,
- // (newValue, oldValue) => {
- // // if(newValue){
- // // options.xAxis[0].data = newValue.map(item => item[1] + item[2])
- // // options.series[0].data = newValue.map(item => Math.floor(item[3]))
- // // }
- // myChart.value.setOption(options);
- // }
- // );
- const initChart = () => {
- myChart.value = echarts.init(chartDom.value);
- myChart.value.setOption(options);
- };
- </script>
- <style lang="scss" scoped>
- .chart {
- width: 100%;
- height: 100%;
- }
- </style>
|