格式化Echarts的X轴显示,设置显示间隔

业务需求:x轴间隔4个显示,并且末尾显示23时

x轴为写死的0时-23时,使用Array.from

data: Array.from({ length: 24 }).map((_, i) => `${i}时`)

需要在axisLabel 里使用 interval: 0, // 强制显示所有刻度标签,然后通过 formatter 函数控制只显示每 4 个刻度和最后一个刻度。

formatter(value, index) { if (index % 4 === 0 || index === 23) { // 每 4 个刻度显示一次,最后一个刻度始终显示 return value; } else { return ''; } } },

 表格的基础项chartOptions.js


import * as echarts from 'echarts';

export function chartOption() {
  return {
    title: {
      text: `X:时间(h) / Y:温度(℃)`,
      left: 'center',
      top: 0,
      textStyle: {
        fontSize: 14,
        fontFamily: 'MicrosoftYaHei',
        // color: '#1E5DFF',
      }
    },
    replaceMerge: ['series'],
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        crossStyle: {
          color: '#999'
        }
      },
      backgroundColor: ,
      borderColor: ,
      textStyle: {
        color: 
      },
      formatter(params) {
        return `${params[0].axisValueLabel}:${params[0].value} ℃`
      }
    },
    grid: {
      containLabel: true,
      top: 30,
      left: 20,
      right: 20,
      bottom: 0
    },
    xAxis: [
      {
        type: 'category',
        axisLine: {
          onZero: false,
          lineStyle: {
            color: ,
          }
        },
        axisTick: {
          show: false
        },
        
        axisLabel: {
          textStyle: {
            color: ,
            fontSize: 12,
            fontFamily: 'PingFangSC-Regular, PingFang SC',
            fontWeight: 400,
            lineHeight: 17,
          },
          interval: 0, // 强制显示所有刻度标签
          formatter(value, index) {
            if (index % 4 === 0 || index === 23) { // 控制每 4 个刻度显示一次,最后一个刻度始终显示
              return value;
            } else {
              return '';
            }
          }
        },

        data: Array.from({ length: 24 }).map((_, i) => `${i}时`),
      }
    ],
    yAxis: [
      {
        type: "value",
        name: "℃",
        nameTextStyle: {
          padding: [0, -40, -23, -5], // 调整Y轴的单位位置
          color: ,
          fontSize: 12,
          fontFamily: 'PingFangSC-Regular, PingFang SC',
          fontWeight: 400,
          lineHeight: 17,
        },
        splitLine: {
          show: false,
        },
        axisTick: {
          show: false
        },
        axisLine: {
          show: true,
          lineStyle: {
            color: ,
          }
        },
        axisLabel: {
          show: true,
          textStyle: {
            color: ,
            fontSize: 12,
            fontFamily: 'PingFangSC-Regular, PingFang SC',
            fontWeight: 400,
            lineHeight: 17,
          }
        },
      },
    ],
    series: [
      {
        name: "",
        type: "line",
        smooth: true, //平滑曲线显示
        symbol: "none", // 去掉圆点
        lineStyle: {
          color: "#00FFB8",
          width: 2,
        },
        data: []
      },
    ]
  }
};

表格的数据结构

backupTempTableData: [
        { timeName1: '0时', tempValue1: '0.00', timeName2: '8时', tempValue2: '0.00', timeName3: '16时', tempValue3: '00.00' },
        { timeName1: '1时', tempValue1: '0.00', timeName2: '9时', tempValue2: '0.00', timeName3: '17时', tempValue3: '00.00' },
        { timeName1: '2时', tempValue1: '0.00', timeName2: '10时', tempValue2: '0.00', timeName3: '18时', tempValue3: '00.00' },
        { timeName1: '3时', tempValue1: '0.00', timeName2: '11时', tempValue2: '0.00', timeName3: '19时', tempValue3: '00.00' },
        { timeName1: '4时', tempValue1: '0.00', timeName2: '12时', tempValue2: '0.00', timeName3: '20时', tempValue3: '00.00' },
        { timeName1: '5时', tempValue1: '0.00', timeName2: '13时', tempValue2: '0.00', timeName3: '21时', tempValue3: '00.00' },
        { timeName1: '6时', tempValue1: '0.00', timeName2: '14时', tempValue2: '0.00', timeName3: '22时', tempValue3: '00.00' },
        { timeName1: '7时', tempValue1: '0.00', timeName2: '15时', tempValue2: '0.00', timeName3: '23时', tempValue3: '00.00' },
      ],

后台请求的数据是一个数组[ ],表示0-23时的数据,所以需要把数组的值赋值给表格,

[
  45.1,
  45.11,
  45.12,
  45.13,
  45.14,
  45.15,
  45.16,
  45.17,
  45.18,
  45.19,
  45.2,
  45.21,
  45.22,
  45.23,
  45.24,
  45.25,
  45.26,
  45.27,
  45.28,
  45.29,
  45.3,
  "",
  "",
  ""
]

     initData() {
        // 请求数据库值
        getCmdInitData().then(res => {
          const varr = res?.data; // []
          state.backupTempTableData.forEach((item, index) => {
             item.tempValue1 = Number(varr[index]).toFixed(2) || '0.00'
             item.tempValue2 = Number(varr[index + 8]).toFixed(2) || '0.00'
             item.tempValue3 = Number(varr[index + 16]).toFixed(2) || '0.00'
           })
          }
        })
      },

当表格的数据修改后,需要重新把表格数据再提取成数组,赋值给Y轴

     <!-- 表格设置 -->
          <vxe-table border stripe :data="timeTempTable" :edit-config="{ trigger: 'click', mode: 'cell' }">
            <vxe-column field="timeName1" title="时间" width="60" align="center"></vxe-column>
            <vxe-column field="tempValue1" title="温度℃" width="90" align="center" :edit-render="{ autofocus: '' }">
              <template #edit="{ row }">
                <vxe-input v-model="row.tempValue1" type="float" digits="2" :min="-100" :max="100"
                  placeholder="0.00"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="timeName2" title="时间" width="60" align="center"></vxe-column>
            <vxe-column field="tempValue2" title="温度℃" width="90" align="center"
              :edit-render="{ autofocus: '.vxe-input--inner' }">
              <template #edit="{ row }">
                <vxe-input v-model="row.tempValue2" type="float" digits="2" :min="-100" :max="100"
                  placeholder="0.00"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="timeName3" title="时间" width="60" align="center"></vxe-column>
            <vxe-column field="tempValue3" title="温度℃" width="90" align="center"
              :edit-render="{ autofocus: '.vxe-input--inner' }">
              <template #edit="{ row }">
                <vxe-input v-model="row.tempValue3" type="float" digits="2" :min="-100" :max="100"
                  placeholder="0.00"></vxe-input>
              </template>
            </vxe-column>
          </vxe-table>

<Echart :options="lineChartData" ref="echartRef" />

import { chartOption } from './chartOptions'
echartRef: null,
lineChartData: {},
backupTempTableData: [
        { timeName1: '0时', tempValue1: '0.00', timeName2: '8时', tempValue2: '0.00', timeName3: '16时', tempValue3: '00.00' },
        { timeName1: '1时', tempValue1: '0.00', timeName2: '9时', tempValue2: '0.00', timeName3: '17时', tempValue3: '00.00' },
        { timeName1: '2时', tempValue1: '0.00', timeName2: '10时', tempValue2: '0.00', timeName3: '18时', tempValue3: '00.00' },
        { timeName1: '3时', tempValue1: '0.00', timeName2: '11时', tempValue2: '0.00', timeName3: '19时', tempValue3: '00.00' },
        { timeName1: '4时', tempValue1: '0.00', timeName2: '12时', tempValue2: '0.00', timeName3: '20时', tempValue3: '00.00' },
        { timeName1: '5时', tempValue1: '0.00', timeName2: '13时', tempValue2: '0.00', timeName3: '21时', tempValue3: '00.00' },
        { timeName1: '6时', tempValue1: '0.00', timeName2: '14时', tempValue2: '0.00', timeName3: '22时', tempValue3: '00.00' },
        { timeName1: '7时', tempValue1: '0.00', timeName2: '15时', tempValue2: '0.00', timeName3: '23时', tempValue3: '00.00' },
      ],


 initData() {
        // 请求数据库值,赋值给表格
        getCmdInitData().then(res => {
          const varr = res?.data; // []
          state.backupTempTableData.forEach((item, index) => {
             item.tempValue1 = Number(varr[index]).toFixed(2) || '0.00'
             item.tempValue2 = Number(varr[index + 8]).toFixed(2) || '0.00'
             item.tempValue3 = Number(varr[index + 16]).toFixed(2) || '0.00'
           })
          }
        })
      },


// Y轴数据转换为数组
      getYData(data) {
        let result1 = [];
        let result2 = [];
        let result3 = [];
        let yData = []
        // 循环遍历每个对象
        for (const obj of data) {
          const temp1 = obj.tempValue1 || '0.00'
          const temp2 = obj.tempValue2 || '0.00'
          const temp3 = obj.tempValue3 || '0.00'
          result1.push(temp1);
          result2.push(temp2);
          result3.push(temp3);
        }
        yData = [...result1, ...result2, ...result3]
        return yData;
      },
    }

    // 监听table数据更新,刷新下发命令体内容
    watch(
      () => state.backupTempTableData,
      () => {
        state.lineChartData = chartOption();
        let yData = methods.getYData(state.backupTempTableData)
        // console.log(yData, '--yData--');
        set(state.lineChartData, 'series[0].data', yData); // 设置y轴数据
      }, {
        deep: true,
      }
    )

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/254084.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【Axure教程】区间评分条

区间评分条是一种图形化的表示工具&#xff0c;用于展示某一范围内的数值或分数&#xff0c;并将其划分成不同的区间。这种评分条通常用于直观地显示数据的分布或某个指标的表现。常用于产品评价、调查和反馈、学术评价、健康评估、绩效评估、满意度调查等场景。 所以今天作者…

大语言模型加速信创软件 IDE 技术革新

QCon 全球软件开发大会&#xff08;上海站&#xff09;将于 12 月 28-29 日举办&#xff0c;会议特别策划「智能化信创软件 IDE」专题&#xff0c;邀请到华为云开发工具和效率领域首席专家、华为软件开发生产线 CodeArts 首席技术总监王亚伟担任专题出品人&#xff0c;为专题质…

bottom-up-attention-vqa-master 成功复现!!!

代码地址 1、create_dictionary.py 建立词典和使用预训练的glove向量 &#xff08;1&#xff09;create_dictionary() 遍历每个question文件取出所关注的question部分&#xff0c;qs 遍历qs&#xff0c;对每个问题的文本内容进行分词&#xff0c;并将分词结果添加到字典中&…

解决飞书文档导出word后公式乱码/不可显示问题

目录 项目场景: 原因分析: 解决方案: 项目场景: 飞书文档导出为word: 但是公式会出现在word中无法显示、乱码等问题。 原因分析: 飞书做的有点菜

智能优化算法应用:基于静电放电算法3D无线传感器网络(WSN)覆盖优化 - 附代码

智能优化算法应用&#xff1a;基于静电放电算法3D无线传感器网络(WSN)覆盖优化 - 附代码 文章目录 智能优化算法应用&#xff1a;基于静电放电算法3D无线传感器网络(WSN)覆盖优化 - 附代码1.无线传感网络节点模型2.覆盖数学模型及分析3.静电放电算法4.实验参数设定5.算法结果6.…

DS哈希查找—线性探测再散列

Description 定义哈希函数为H(key) key%11&#xff0c;输入表长&#xff08;大于、等于11&#xff09;。输入关键字集合&#xff0c;用线性探测再散列构建哈希表&#xff0c;并查找给定关键字。 –程序要求– 若使用C只能include一个头文件iostream&#xff1b;若使用C语言…

Java_Lambda表达式JDK8新特性(方法引用)

一、Lambda表达式 接下来&#xff0c;我们学习一个JDK8新增的一种语法形式&#xff0c;叫做Lambda表达式。作用&#xff1a;用于简化匿名内部类代码的书写。 1.1 Lambda表达式基本使用 怎么去简化呢&#xff1f;Lamdba是有特有的格式的&#xff0c;按照下面的格式来编写Lamd…

FPGA实现 TCP/IP 协议栈 客户端 纯VHDL代码编写 提供4套vivado工程源码和技术支持

目录 1、前言版本更新说明免责声明 2、相关方案推荐我这里已有的以太网方案1G 千兆网 TCP-->服务器 方案10G 万兆网 TCP-->服务器客户端 方案常规性能支持多节点FPGA资源占用少数据吞吐率高低延时性能 4、TCP/IP 协议栈代码详解代码架构用户接口代码模块级细讲顶层模块PA…

腾讯地图绘画多边形和计算面积

<!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-scale1.0" /><title>地图</title></head><script src…

将加速度计当作麦克风来听振动

我们都知道&#xff0c;用麦克风来捕捉声音时&#xff0c;最大的挑战是&#xff1a;背景噪音。这背景噪音有&#xff0c;车辆行驶中的风噪、车辆所处周围的环境的声音&#xff08;人声、车间其它声音&#xff09;、车辆其它部件正常工作的声音。 我们测用加速度计测振动时&…

Flink系列之:监控反压

Flink系列之&#xff1a;监控反压 一、反压二、Task 性能指标三、示例四、反压状态 Flink Web 界面提供了一个选项卡来监控正在运行 jobs 的反压行为。 一、反压 如果你看到一个 task 发生 反压警告&#xff08;例如&#xff1a; High&#xff09;&#xff0c;意味着它生产数…

CTF竞赛密码学题目解析

CTF&#xff08;Capture The Flag&#xff09;竞赛是一个有趣的挑战。密码学是CTF竞赛中的核心元素之一&#xff0c;通常涉及解密、破译密码、理解加密算法等技能。以下是30个题目及答案&#xff0c;新入行的可以看看鸭。 题目及答案 1. Caesar Cipher 描述&#xff1a;给出一…

【JavaEE】多线程(5) -- 阻塞队列

目录 1.阻塞队列是什么? 2.生产者消费者模型 3.标准库中的阻塞队列 4.阻塞队列的实现 1.阻塞队列是什么? 阻塞队列是⼀种特殊的队列. 也遵守 "先进先出" 的原则 阻塞队列能是⼀种线程安全的数据结构, 并且具有以下特性: 当队列满的时候, 继续⼊队列就会阻塞, …

论文阅读二——基于全脸外观的凝视估计

论文阅读二——基于全脸外观的凝视估计 基础知识主要内容文章中需要学习的架构AlexNet 代码复现 该论文是2017年在CVPR中发表的一篇关于 “gaze estimation” 的文章&#xff0c;其论文地址与代码地址如下&#xff1a; 论文地址 代码地址 论文特点&#xff1a;文章提出了一种…

IT和业务部门都想要的数据摆渡产品是这样的!

企业只要进行了网络隔离&#xff0c;就必然会需要数据摆渡相关产品&#xff0c;不管是免费的也好&#xff0c;专业收费的也好&#xff0c;总之都是需要将数据流转起来进行使用。 传统的数据摆渡产品也不少&#xff0c;比如FTP&#xff0c;甚至是U盘拷贝&#xff0c;在功能上来说…

Java数组(2)

我是南城余&#xff01;阿里云开发者平台专家博士证书获得者&#xff01; 欢迎关注我的博客&#xff01;一同成长&#xff01; 一名从事运维开发的worker&#xff0c;记录分享学习。 专注于AI&#xff0c;运维开发&#xff0c;windows Linux 系统领域的分享&#xff01; 本…

Docker容器如何优雅地访问宿主机网络

# 前言 某些时候&#xff0c;我们会有在容器内容访问宿主机某个服务的需求&#xff0c;比如现在 openai 无法直接访问&#xff0c;需要给项目添加代理&#xff0c;我的 chatgpt-dingtalk (opens new window) 项目支持了通过环境变量指定代理地址。 添加方式如下&#xff1a; …

微信小程序(五)地图

一、引言 作者开发《目的地到了》需要满足用户选取地址作为目的地的需求&#xff0c;所以需要使用到地图。作者用的是腾讯地图&#xff0c;这里介绍下技术实现。 二、引包 引入腾讯地图的组件包微信小程序JavaScript SDK | 腾讯位置服务&#xff0c;根据经纬度调用里面的api才…

5款不可或缺的办公软件,好用且使用频率超高,几乎每个人都需要

在当今数字化时代&#xff0c;办公软件成为了现代职场必备的工具。这些软件可以大大提高我们的办公效率&#xff0c;简化工作流程&#xff0c;使我们更加高效地完成任务。今天给大家分享5款不可或缺的办公软件&#xff0c;它们不仅好用&#xff0c;而且使用频率极高&#xff0c…

【PWN】学习笔记(三)【返回导向编程】(中)

目录 课程回顾动态链接过程 课程 课程链接&#xff1a;https://www.bilibili.com/video/BV1854y1y7Ro/?vd_source7b06bd7a9dd90c45c5c9c44d12e7b4e6 课程附件&#xff1a; https://pan.baidu.com/s/1vRCd4bMkqnqqY1nT2uhSYw 提取码: 5rx6 回顾 管道符 | 把前一个指令的输出作…