当前位置: 首页 > news >正文

【Echarts】使用多横坐标轴展示近十五天天气预报

现在手机都有天气app,使用echarts展示十五天天气预报的需要你遇到过这样离大谱的需求吗?如果没有或许你能从中找到些许思路。

效果

请添加图片描述
看效果是不是有点那么个意思,开局一张图,代码全靠ctrl + c。不多说上代码。

vue模板引擎代码

<template><div ref="xAxisChartRef" class="chart"></div>
</template>
<script setup lang="ts">import { onMounted, ref } from 'vue';import { useECharts } from '@/utils';import { options } from './options';let chart: EChartsType;const xAxisChartRef = ref();onMounted(() => {chart = useECharts(xAxisChartRef.value, options);});
</script><style lang="less" scoped>.chart {height: 300px;background: linear-gradient(90deg, #dde4ff, #fff, #fff, #dde4ff);}
</style>

图表配置

import mock from 'mockjs';
import clear from './assets/clear.png';
import cloudy from './assets/cloudy.png';
import rainy from './assets/rainy.png';
import thundershower from './assets/thundershower.png';
import type { EChartsType } from 'echarts';
const weather = [clear, cloudy, rainy, thundershower];
export const optons = {
tooltip: {trigger: 'none',axisPointer: {type: 'cross',},
},
grid: {top: 80,left: 30,bottom: 50,right: 30,
},
xAxis: [{type: 'category',boundaryGap: false,position: 'top',offset: 50,axisLine: {show: false,},axisTick: {show: false,},axisLabel: {interval: 0,formatter: ['{a|{value}}'].join('\n'),rich: {a: {fontSize: 13,},},},nameTextStyle: {},data: Array.from({ length: 15 }, (_, i) => {const day = new Date().getDate();const date = new Date(new Date().setDate(day + i));return `${date.getMonth() + 1}/${date.getDate()}`;}),},{type: 'category',boundaryGap: false,position: 'top',offset: 32,axisLine: {show: false,},axisTick: {show: false,},axisLabel: {interval: 0,formatter: ['{a|{value}}'].join('\n'),rich: {a: {// color: 'white',fontSize: 12,},},},nameTextStyle: {fontWeight: 'bold',fontSize: 19,},data: Array.from({ length: 15 }, (_, i) => {const day = new Date().getDate();const date = new Date(new Date().setDate(day + i));const week = ['日', '一', '二', '三', '四', '五', '六'];return `${week[date.getDay()]}`;}),},{type: 'category',boundaryGap: false,position: 'top',offset: 32,axisLine: {show: false,},axisTick: {show: false,},axisLabel: {interval: 0,formatter: ['{a|{value}}'].join('\n'),rich: {a: {// color: 'white',fontSize: 12,},},},nameTextStyle: {fontWeight: 'bold',fontSize: 19,},data: Array.from({ length: 15 }, (_, i) => {const day = new Date().getDate();const date = new Date(new Date().setDate(day + i));const week = ['日', '一', '二', '三', '四', '五', '六'];return `${week[date.getDay()]}`;}),},{type: 'category',boundaryGap: false,position: 'top',offset: -24,axisLine: {show: false,},axisTick: {show: false,},axisLabel: {interval: 0,formatter: function (value, index) {return '{' + index + '| }\n{b|' + value + '}';},rich: {...Array.from({ length: 15 }, () => ({backgroundColor: {image: weather[mock.Random.integer(0, 3)],},height: 16,})),b: {fontSize: 11,lineHeight: 30,height: 20,},},},nameTextStyle: {fontWeight: 'bold',fontSize: 19,},data: Array.from({ length: 15 },() =>['小雨', '阴', '多云', '小雨', '晴', '雨夹雪'][mock.Random.integer(0, 5)]),},{type: 'category',boundaryGap: false,position: 'bottom',offset: -5,axisLine: {show: false,},axisTick: {show: false,},axisLabel: {interval: 0,formatter: function (value, index) {return '{' + index + '| }\n{b|' + value + '}';},rich: {...Array.from({ length: 15 }, () => ({backgroundColor: {image: weather[mock.Random.integer(0, 3)],},height: 16,})),b: {fontSize: 11,lineHeight: 30,height: 20,},},},nameTextStyle: {fontWeight: 'bold',fontSize: 19,},data: Array.from({ length: 15 },() =>['小雨', '阴', '多云', '小雨', '晴', '雨夹雪'][mock.Random.integer(0, 5)]),},
],
yAxis: [{type: 'value',boundaryGap: true,show: false,scale: true,},
],
series: [{name: '最高气温',type: 'line',emphasis: {focus: 'series',},lineStyle: {color: '#FF8A15',},itemStyle: {color: '#FF8A15',},data: Array.from({ length: 24 },() => `${mock.Random.integer(18, 29)}`),},{name: '最低气温',type: 'line',emphasis: {focus: 'series',},lineStyle: {color: '#0091FF',},itemStyle: {color: '#0091FF',},data: Array.from({ length: 24 }, () => mock.Random.float(9, 17)),},
],
}

实际效果地址

  • demo

http://www.mrgr.cn/news/26754.html

相关文章:

  • AgentOhana:为智能体学习设计统一的数据和训练流水线
  • 17、电科院FTU检测标准学习笔记-录波性能
  • 现代 Web 开发工具箱:Element-UI 表单组件全攻略(一)
  • AI大模型在知识管理平台上的应用:泛微·采知连实现自动采集.精准搜索.智能问答.主动推荐
  • 常见的站长工具接口有哪些?站长们该如何选择?
  • 在国行iOS设备上启用Apple Intelligence
  • 如何从 Git 克隆项目并推送到新的仓库(包含所有的代码和提交记录)
  • 将数据库系统实践转向AI:使用生成式AI创建高效的开发和维护实践
  • Mysql JSON结果不能IN
  • C#实现串口中继
  • 原生js案例之面向对象的tab切换
  • 前端层面----监控与埋点
  • APP广告变现流量售卖,选择API还是SDK对接?
  • Auracast认证:蓝牙广播音频的革新之旅
  • 水位雨量自动监测站的工作原理
  • 基于TRIZ的救援机器人轻量化设计
  • 刚刚!1区top“灌水”神刊,39天Accepted!真正的沾边可录
  • 828华为云征文|华为云Flexus云服务器X实例部署Servas自托管书签管理工具
  • 揭秘高效日志管理:解锁数据宝藏,驱动业务精准决策
  • Java集合相关面试题