echarts 实现水利计算模型-雨量,流量,时间分割线

news2024/9/23 21:23:49

  • 需求背景
  • 解决效果
  • ISQQW代码地址
  • index.vue

需求背景

实现水利计算模型-雨量,流量,时间分割线

解决效果

在这里插入图片描述

ISQQW代码地址

链接

index.vue

<!--/**
* @author: liuk
* @date: 2024/06/13
* @describe: 水利计算模型图表
*/-->
<template>
  <div ref="chatDom" class="sectionalResultChart"></div>
</template>

<script lang="ts" setup>
import {ref, onMounted, watch, nextTick, defineProps} from "vue"
import * as echarts from 'echarts'
import moment from 'moment'

import {formatToFixed} from "@/utils/dictionary"
// Props
const props = defineProps(['data'])

import {usefloodForecastStore} from "@/store/modules/floodForecast";

const floodForecastStore = usefloodForecastStore()

let myChart = null // Vue3 使用 proxy 对象代理,而 echarts 则使用了大量的全等(===), 对比失败从而导致了bug。
const chatDom = ref(null)
const isWrank = ref(false) // 最大值是否超出1w

watch(() => props.data, (data) => {
  const temp = data.map(item => {
    const {historyFlow, hdlflow, ddrmflow, xajflow, siflow, lstmflow} = item
    return Object.values({historyFlow, hdlflow, ddrmflow, xajflow, siflow, lstmflow})
  }).flat()
  const maxValue = Math.max.apply(null, temp)
  isWrank.value = maxValue >= 1e4

  nextTick(() => {
    drawChart()
    myChart.showLoading({
      text: '加载中...',  // 加载提示文本
      color: '#fff',   // 加载动画颜色
      textColor: '#fff',  // 文字颜色
      maskColor: 'rgba(41, 12, 12, .5)',  // 遮罩颜色
      zlevel: 0           // z轴层级
    })
    if (data.length) {
      myChart.hideLoading();
      const option = myChart.getOption()
      myChart.clear()
      myChart.setOption(renderFn(option, data))
    }
  })
}, {immediate: true})

const renderFn = (option, data) => {
  const curForecastTime = floodForecastStore.curSelectObj.forecastTime || ''
  const len = data.length // 数据总长度
  let curDivisionHourNum = Math.max(data.findIndex(item => moment(item.time).valueOf() === moment(curForecastTime).valueOf()), 0) // 分割线位置
  debugger
  option.legend[0].data = ['面雨量', '实测流量', '混合深度学习', 'DDRM', '新安江', '时空异构', 'LSTM']
  option.xAxis[0].data = data.map(item => item.time)
  option.yAxis[0].name = isWrank.value ? '流量 万m³/s' : '流量 m³/s'
  option.yAxis[1].max = Math.max.apply(null,data.map(item => formatToFixed(item.rainfallValue) || 0)) * 3
  option.series[0].data = data.map(item => formatToFixed(item.rainfallValue) || 0)//面雨量
  option.series[1].data = data.map(item => formatToFixed(item.historyFlow) || 0)//实测流量
  option.series[2].data = data.slice(0, curDivisionHourNum).fill('-').concat(data.slice(curDivisionHourNum).map(item => formatToFixed(item.hdlflow) || 0))//混合深度学习
  option.series[3].data = data.slice(0, curDivisionHourNum).fill('-').concat(data.slice(curDivisionHourNum).map(item => formatToFixed(item.ddrmflow) || 0))//DDRM
  option.series[4].data = data.slice(0, curDivisionHourNum).fill('-').concat(data.slice(curDivisionHourNum).map(item => formatToFixed(item.xajflow) || 0))//新安江
  option.series[5].data = data.slice(0, curDivisionHourNum).fill('-').concat(data.slice(curDivisionHourNum).map(item => formatToFixed(item.siflow) || 0))//时空异构
  option.series[6].data = data.slice(0, curDivisionHourNum).fill('-').concat(data.slice(curDivisionHourNum).map(item => formatToFixed(item.lstmflow) || 0))//LSTM
  // ------- 虚线
  option.series[7].data = data.slice(0, curDivisionHourNum + 1).map(item => formatToFixed(item.hdlflow) || 0)//混合深度学习
  option.series[8].data = data.slice(0, curDivisionHourNum + 1).map(item => formatToFixed(item.ddrmflow) || 0)//DDRM
  option.series[9].data = data.slice(0, curDivisionHourNum + 1).map(item => formatToFixed(item.xajflow) || 0)//新安江
  option.series[10].data = data.slice(0, curDivisionHourNum + 1).map(item => formatToFixed(item.siflow) || 0)//时空异构
  option.series[11].data = data.slice(0, curDivisionHourNum + 1).map(item => formatToFixed(item.lstmflow) || 0)//LSTM
  // ----- 定位分割线
  option.series[12].data = new Array(len).fill(0.1)
  option.series[12].data[curDivisionHourNum] = 0
  const curHeight = parseInt(window.getComputedStyle(chatDom.value).height)
  switch (true) {
    case curHeight >= 600:
      option.series[12].markPoint.symbolSize = [1.5, 515]
      option.series[12].markPoint.symbolOffset = [0, -257]
      break
    case curHeight > 460:
      option.series[12].markPoint.symbolSize = [1.5, 385]
      option.series[12].markPoint.symbolOffset = [0, -192]
      break
    default:
      option.series[12].markPoint.symbolSize = [1.5, 200]
      option.series[12].markPoint.symbolOffset = [0, -100]
  }

  return option
}

onMounted(() => {
  window.addEventListener('resize', () => {
    drawChart()
    const option = myChart.getOption()
    myChart.clear()
    myChart.setOption(renderFn(option, props.data,))
  }, {passive: true});
})

const drawChart = () => {
  let chartDom = chatDom.value
  if (chartDom == null) {
    return
  }
  echarts.dispose(chartDom)
  myChart = echarts.init(chartDom)
  const option = {
        color: ['rgba(46, 165, 255, 1)', 'rgba(0, 0, 255, 1)', 'rgba(0, 207, 19, 1)', 'rgba(254, 254, 62, 1)', 'rgba(244, 106, 87, 1)', 'rgba(255, 162, 0, 1)', 'rgba(247, 0, 237, 1)'],
        tooltip: {
          trigger: 'axis',
          padding: [0, 10, 10, 10],
          axisPointer: {
            type: 'shadow',
            label: {
              show: true,
            },
          },
          formatter: function (param) {
            let data = param.filter(item => item.data !== '-' && item.seriesName !== "定位分割线")
            data = data.filter((item, i) => data.findIndex(x => x.seriesName === item.seriesName) === i)
            return `
          <div class="sectionalResultChart-popup">
            <p class="top">
                <span>${param[0]?.axisValue} </span>
            </p>
            ${
                data.map(item => {
                  let unit
                  switch (true) {
                    case ['面雨量'].includes(item.seriesName):
                      unit = 'mm';
                      break
                    default:
                      unit = 'm³/s'
                      break
                  }
                  return `
                  <p class="item">
                      <i class="icon" style="background-color:${item.color}"></i>
                      <span class="name">${item.seriesName}</span>
                      <span class="value"><b>${item.data || 0}</b>${item.data !== '--' ? unit : ''}</span>
                  </p>`
                }).join("")
            }
          </div>
        `
          }
        },
        dataZoom: [
          {
            type: 'inside'
          }
        ],
        grid: {
          left: 45,
          top: 40,
          right: 40,
          bottom: 40,
          splitLine: {
            show: true,
            lineStyle: {
              color: 'rgba(0, 0, 0, 0.1)',
              type: 'dashed'
            }
          }
        },
        legend: {
          data: [],
          top: 5,
          icon: 'circle',
          textStyle: {
            color: '#fff'
          },
        },
        xAxis: {
          type: 'category',
          data: ['2021/06/25', '2021/06/25', '2021/06/25', '2021/06/25', '2021/06/25', '2021/06/25', '2021/06/25',],
          alignTicks: true,
          axisLine: {
            lineStyle: {
              color: '#ccc'
            }
          },
          splitLine: {
            show: false,
            lineStyle: {
              width: 1,
              color: '#eee',
            },
          },
          axisTick: {
            alignWithLabel: true,
          },
          axisLabel: {
            margin: 10,
            textStyle: {
              color: '#eee',
              fontSize: 14,
            },
            formatter: (val) => moment(val).format('HH:mm')
          },
        },
        yAxis: [
          {
            type: 'value',
            name: '流量 m³/s',
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            nameTextStyle: {
              color: '#fff'
            },
            splitLine: {
              show: false
            },
            axisLabel: {
              color: '#fff',
              formatter: (val) => isWrank.value ? formatToFixed(val / 1e4, 1) : val
            },
          },
          {
            type: 'value',
            name: '面雨量 mm',
            nameLocation: 'start',
            inverse: true,
            nameTextStyle: {
              color: '#fff'
            },
            splitLine: {
              show: false
            },
            axisLabel: {
              color: '#fff',

            },
          }
        ],
        series: [
          {
            name: '面雨量',
            type: 'bar',
            data: [],
            yAxisIndex: 1,
            itemStyle: {
              borderRadius: [0, 0, 5, 5]
            },
          },
          {
            name: '实测流量',
            smooth: true,
            type: 'line',
            showSymbol: false,
            barWidth: '30%',
            data: [],
            yAxisIndex: 0,
          },
          {
            name: '混合深度学习',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            yAxisIndex: 0,
          },
          {
            name: 'DDRM',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            yAxisIndex: 0,
          },
          {
            name: '新安江',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            yAxisIndex: 0,
          },
          {
            name: '时空异构',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            yAxisIndex: 0,
          },
          {
            name: 'LSTM',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            yAxisIndex: 0,
          },
          // 虚线 -------------
          {
            name: '混合深度学习',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            lineStyle: {
              type: 'dashed'
            },
            yAxisIndex: 0,
          },
          {
            name: 'DDRM',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            lineStyle: {
              type: 'dashed'
            },
            yAxisIndex: 0,
          },
          {
            name: '新安江',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            lineStyle: {
              type: 'dashed'
            },
            yAxisIndex: 0,
          },
          {
            name: '时空异构',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            lineStyle: {
              type: 'dashed'
            },
            yAxisIndex: 0,
          },
          {
            name: 'LSTM',
            type: 'line',
            smooth: true,
            showSymbol: false,
            barWidth: '30%',
            data: [],
            lineStyle: {
              type: 'dashed'
            },
            yAxisIndex: 0,
            markLine: {
              silent: true,
              lineStyle: {
                type: 'solid',
                color: 'red',
              },
              data: 2
            },
          },
          //定位分割线 ---------------
          {
            name: '定位分割线',
            smooth: true,
            type: 'line',
            showSymbol: false,
            barWidth: '30%',
            color: 'transparent',
            data: ['0.1', '0.1', 0.1, 0.1, 0.1, 0.1, 0.1, 0, 0.1],
            yAxisIndex: 0,
            markPoint: {
              symbol: 'rect',
              symbolSize: [1.5, 600],
              symbolOffset: [0, -215],
              data: [
                {
                  type: 'min',
                  itemStyle: {
                    color: 'red'
                  },
                  label: {
                    show: true,
                    color: 'red',
                    position: 'top',
                    formatter: '预报作业时间',
                    fontSize: 12,
                  },
                  emphasis: {
                    disabled: true
                  }
                },
              ],
            },
          },
        ],
      };
  option && myChart.setOption(option)
}

</script>

<style lang="scss" scoped>
.sectionalResultChart {
  width: 100%;
  height: 100%;
  max-height: 600px;
}
</style>

<style lang="scss">
.sectionalResultChart-popup {
  overflow: hidden;
  //margin: 3px 10px;

  .top {
    //margin-bottom: 16px;
    font-weight: bold;
  }

  .item {
    display: flex;
    align-items: center;
    margin: 10px 0;

    &:last-child {
      margin-bottom: 0;
    }

    .icon {
      display: inline-block;
      width: 12px;
      height: 12px;
      margin-right: 10px;
      border-radius: 50%;
    }

    .name {
      width: 90px;
      margin-right: 10px;
    }

    .value {
      flex: 1;
      text-align: right;
    }
  }
}
</style>

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

快速创建一个AI应用

千帆官网&#xff1a;https://console.bce.baidu.com/qianfan/overview 完成的demo&#xff1a;https://dog-tired.github.io/spage_ai/ 这篇博客主要讲述使用千帆免费的大模型接口简单的html页面创建一个AI问答机器人 平台能力 选择使用千帆的speed系列模型&#xff0c;免费…

SpringBoot整合MybatisPlus(详细版)

MybatisPlus简介 1. MybatisPlus 2. 特点 SpringBoot整合MybatisPlus 1. 新建SpringBoot工程 2. 数据准备 3. 引入依赖 4. 配置文件 5. 用MyBatisX-Generator生成代码 整体结构 User类 UserMapper UserServiceImpl UserController类 测试 查询用户表中全部信息 …

Flutter 状态管理新境界:多Provider并行驱动UI

前言 在上一篇文章中&#xff0c;我们讨论了如何使用 Provider 在 Flutter 中进行状态管理。 本篇文章我们来讨论如何使用多个 Provider。 在 Flutter 中&#xff0c;使用 Provider 管理多个不同的状态时&#xff0c;你可以为每个状态创建一个单独的 ChangeNotifierProvider…

C++初学者指南-5.标准库(第一部分)--容器遍历

C初学者指南-5.标准库(第一部分)–容器遍历 文章目录 C初学者指南-5.标准库(第一部分)--容器遍历前向遍历基于范围的循环for_each / for_each_n迭代器的显式使用基于索引的循环 逆向遍历反向范围循环(C20)反向 for_each / for_each_n反向迭代器的显式使用基于索引的反向循环…

2024年TOGAF考试预约流程(纯净版本)

TOGAF考试如何报名&#xff1f;TOGAF考试报名流程是什么&#xff1f;很多文章虽然都有指出来&#xff0c;但是并不明确指出具体流程 今天我们跟着艾威小编一起来看一下这篇纯净版2024年TOGAF考试预约流程&#xff0c;今天我们直说考试报名流程。 01登录官方网址 如果没账号就…

TCP传输控制协议二

TCP 是 TCP/IP 模型中的传输层一个最核心的协议&#xff0c;不仅如此&#xff0c;在整个 4 层模型中&#xff0c;它都是核心的协议&#xff0c;要不然模型怎么会叫做 TCP/IP 模型呢。 它向下使用网络层的 IP 协议&#xff0c;向上为 FTP、SMTP、POP3、SSH、Telnet、HTTP 等应用…

MySQL—— if/cast/case.... end/md5 函数

目录 1. if 使用 2. if 嵌套 ​3. case ... end 4. 类型转换 cast&#xff08;&#xff09; 5. 加密函数 md5&#xff08;&#xff09; 1. if 使用 将姓名为smith的员工工资上调10%&#xff1b; 2. if 嵌套 如果岗位是manager&#xff0c;工资上调10%&#xff0c;如果岗位是s…

收到赵健老师的限量签名书,开心

收到赵老师的亲笔签名&#x1f4d6;&#xff0c;开心一下下[愉快]&#xff0c;由外而内&#xff0c;首先是我喜欢的线装书&#xff0c;展开阅读舒适&#xff0c;手感友好&#xff0c;纸张更是很讲究&#xff0c;密度很高也很温润&#xff0c;应该是进口纸&#xff0c;每个对页的…

前端简历:项目经历(经验)-外卖送餐类

项目经历-堂食外送点餐 2022年2月-2022年5月 项目描述&#xff1a;该平台提供外送订餐服务&#xff0c;用户可以在手机中轻松地浏览菜品、下单、支付、编辑地址、填写个人信息等&#xff0c;我主要负责首页、订单、我的这3个功能/模块。 技术栈&#xff1a;Amfe-flexibleAxi…

【BUG】已解决:TypeError: object of type ‘int‘ has no len()

已解决&#xff1a;TypeError: object of type ‘int‘ has no len() 欢迎来到英杰社区https://bbs.csdn.net/topics/617804998 欢迎来到我的主页&#xff0c;我是博主英杰&#xff0c;211科班出身&#xff0c;就职于医疗科技公司&#xff0c;热衷分享知识&#xff0c;武汉城市…

2024 睿抗机器人开发者大赛CAIP-编程技能赛-本科组(省赛)

RC-u1 热҈热҈热҈ 分数 10 全屏浏览 切换布局 作者 DAI, Longao 单位 杭州百腾教育科技有限公司 热҈热҈热҈……最近热得打的字都出汗了&#xff01; 幸好某连锁餐厅开启了气温大于等于 35 度即可获得一杯免费雪碧的活动。但不知为何&#xff0c;在每个星期四的时候&#x…

云渲染服务:初创企业的成本效益与效率提升

视觉营销对于吸引潜在客户至关重要&#xff0c;而云渲染作为一种革命性工具&#xff0c;为创意产业提供了强大的计算能力和灵活性&#xff0c;帮助企业在竞争激烈的市场中脱颖而出。 一、什么是云渲染&#xff1f; 云渲染是指客户利用远程计算资源&#xff0c;将图形传输到云服…

linux虚拟机主ip地址:网络信息不可用(没IP)

第一种情况其它博主写的很详细 就是在 /etc/sysconfig/network-scripts/ifcfg-ens33 的onbootno 改为 yes 然后重启 第二种就是我遇到的&#xff0c;是因为服务没有启动 首先winr打开搜索 然后搜索service.msc 把这两项手工右键开启即可&#xff0c;然后重启虚拟机&a…

SpringCloud网关的实现原理与使用指南

Spring Cloud网关是一个基于Spring Cloud的微服务网关&#xff0c;它是一个独立的项目&#xff0c;可以对外提供API接口服务&#xff0c;负责请求的转发和路由。本文将介绍Spring Cloud网关的实现原理和使用指南。 一、Spring Cloud网关的实现原理 Spring Cloud网关基于Spring…

F. Custom-Made Clothes(武汉icpc邀请赛)

题意&#xff1a;有一个n*n的矩阵&#xff0c;a[i][j]>a[i-1][j],a[i][j]>a[i][j-1](每一行非递减&#xff0c;每一列非递减&#xff09;,每次可以查询a[i][j]是否小于等于x&#xff0c;如果返回1&#xff0c;否则返回0.输出操作&#xff0c;求第k小的最大数。 知识点&a…

在CANopen协议中,SDO的意思

在CANopen协议中&#xff0c;SDO&#xff08;Service Data Object&#xff09;指的是服务数据对象&#xff0c;它是CANopen网络中用于设备配置和参数化的主要机制之一。SDO用于在主站和从站之间传输配置和状态数据&#xff0c;特别适用于传输那些长度超过标准CAN数据帧所能承载…

savgol_filter丢数据点

y_smooth scipy.signal.savgol_filter(src, window_length15, polyorder3, modeconstant, cval15) # 数据变少了 plt.figure(str(i)) plt.plot(x, src, labelsrc) plt.plot(x, y_smooth, labelsmoothed) plt.legend()按照教程&#xff1a;python 数据、曲线平滑处理——方…

【深度学习入门篇 ⑧】关于卷积神经网络

【&#x1f34a;易编橙&#xff1a;一个帮助编程小伙伴少走弯路的终身成长社群&#x1f34a;】 大家好&#xff0c;我是小森( &#xfe61;ˆoˆ&#xfe61; ) &#xff01; 易编橙终身成长社群创始团队嘉宾&#xff0c;橙似锦计划领衔成员、阿里云专家博主、腾讯云内容共创官…

速部署 HBase 测试环境

快速部署 HBase 测试环境 第一步&#xff1a;下载软件&#xff0c;在HBase官网下载最新版&#xff0c; 找到 bin&#xff0c;点击下载&#xff0c;比如我这里下载的是 hbase-2.5.6-bin.tar.gz 第二步&#xff1a;解压软件 $ tar -zxvf hbase-2.5.6-bin.tar.gz $ cd hbase-2.…

完美解决ImportError: cannot import name ‘PILLOW_VERSION‘的正确解决方法,亲测有效!!!

完美解决ImportError: cannot import name PILLOW_VERSION’的正确解决方法&#xff0c;亲测有效&#xff01;&#xff01;&#xff01; 亲测有效 完美解决ImportError: cannot import name PILLOW_VERSION的正确解决方法&#xff0c;亲测有效&#xff01;&#xff01;&#xf…