使用Vue实现数据可视化大屏功能(二)

news2024/10/1 5:38:55

引入数据大屏相关组件

  用Datav插件做大屏可视化的组件,官网地址 http://datav.jiaminghi.com/ ,整个组件库都是基于Vue React版本实现,主要用于构建大屏数据可视化页面,具有很多种类的组件可以使用。其安装方式如下。

npm install @jiaminghi/data-view

全屏容器介绍

  数据可视化页面一般是在浏览器中进行全屏的展示,全屏容器会根据当前的浏览器屏幕窗口大小自动的进行缩放处理,在浏览器全屏之后,整个的全屏容器就会充满全屏。注意在使用之前请将body的margin属性设置为0。Vue中引入代码如下

<template>
    <div id="index">
        <dv-full-screen-container>
            数据可视化
        </dv-full-screen-container>
    </div>
</template>

Loading加载效果

  在数据没有加载完成之前,页面应该处于一个数据加载的状态,这个状态就是由我们的loading组件来实现的。我们可以通过条件判断来引入一个数据加载的组件,当数据加载完成之后,显示数据大屏的组件。

<template>
    <div id="index">
        <dv-loading v-if="loading">数据加载中……</dv-loading>
        <dv-full-screen-container v-else>
            数据可视化
        </dv-full-screen-container>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                loading: true
            }
        },
        mounted(){
          this.cancelLoading();
        },
        methods:{
            cancelLoading(){
                setTimeout(() => {
                    this.loading = false;
                }, 1000);
            }
        }
    }
</script>

边框元素

  在数据可视化大屏上,我们会看到很多的绚丽多彩的边框,在DataV组件中,这些边框都是有SVG元素来进行绘制,默认的组件宽高全部是100%。

dv-border-Box-1
<template>
    <div id="index">
        <dv-full-screen-container class="bg">
            <div style="width: 500px;height: 200px">
                <dv-border-box-1></dv-border-box-1>
            </div>
        </dv-full-screen-container>
    </div>
</template>

  边框效果如下,当然我们也可以通过color 和BackgroudColor来设置颜色。

在这里插入图片描述
  设置颜色和背景颜色。这里的color属性支持配置两个颜色,一个主色,一个副色。

<template>
    <div id="index">
        <dv-full-screen-container class="bg">
            <div style="width: 500px;height: 200px">
                <dv-border-box-1 :color="['red','green']" backgroundColor="blue"></dv-border-box-1>
            </div>
        </dv-full-screen-container>
    </div>
</template>

在这里插入图片描述

项目中引入echarts

  使用如下的命令来引入Echarts组件

npm install echarts -S

使用Vue封装Echarts组件

  在开发数据大屏项目的时候,有可能需要引入大量的Echarts图表,所以可以将Echarts图表封装一下,在使用的时候可以直接使用。首先需要在main.js文件中引入Echarts 然后就是将Echarts挂载到Vue原型上,这样就可以直接使用this.$echarts访问到对应的实例。

引入 echarts
//引入echart
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
创建一个自适应的js文件

  在utils目录中创建一个resizeMixin.js的文件,用来去做大屏的自适应视图,并且创建一个utils/index文件做一个防抖的函数去监听屏幕大小的变化频率。

import { debounce } from '@/utils';
const resizeChartMethod = '$__resizeChartMethod';


export default {
    data() {
        // 在组件内部将图表 init 的引用映射到 chart 属性上
        return {
            chart: null,
        };
    },
    created() {
        window.addEventListener('resize', this[resizeChartMethod], false);
    },
    activated() {
        // 防止 keep-alive 之后图表变形
        if (this.chart) {
            this.chart.resize()
        }
    },
    beforeDestroy() {
        window.removeEventListener('reisze', this[resizeChartMethod]);
    },
    methods: {
        // 防抖函数来控制 resize 的频率
        [resizeChartMethod]: debounce(function() {
            if (this.chart) {
                this.chart.resize();
            }
        }, 300),
    },
};

  创建一个index.js的防抖文件

/**
 * @param {Function} fn 防抖函数
 * @param {Number} delay 延迟时间
 */
export function debounce(fn, delay) {
    var timer;
    return function () {
        var context = this;
        var args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    };
}

创建一个全局的Echarts的组件

  在common文件夹下创建一个Echarts的文件夹创建index.vue的文件,内容如下,并且引入默认的主题文件,这个主题文件在后期也可以替换。

<template>
    <div :id="id" :class="className" :style="{height:height,width:width}"></div>
</template>

<script>
    import tdTheme from "./theme.json"
    import resizeMixins from "@/utils/resizeMixins";

    export default {
        name: "echart",
        mixins: [resizeMixins],
        props: {
            id: {
                type: String,
                default: "chart"
            },
            className: {
                type: String,
                default: 'chart'
            },
            width: {
                type: String,
                default: '100%'
            },
            height: {
                type: String,
                default: '2.5rem'
            },
            options: {
                type: Object,
                default: ()=>({})
            }
        },
        data(){
            return {
                chart:null
            }
        },
        watch:{
            options:{
                handler(options){
                    this.chart.setOption(options,true)
                },
                deep:true
            }
        },
        mounted(){
            // 默认注册主题
            console.log("注册主题",this.$echarts)
            this.$echarts.registerTheme('tdTheme',tdTheme);
            // 初始化Echarts
            this.initChart();
        },
        methods:{
            initChart(){
                this.chart = this.$echarts.init(this.$el,"tdTheme")
                this.chart.setOption(this.options,true)
            }
        }
    }
</script>

<style>

</style>

  默认引入主题样式JSON文件

{
  "color": [
    "#2d8cf0",
    "#19be6b",
    "#ff9900",
    "#E46CBB",
    "#9A66E4",
    "#ed3f14"
  ],
  "backgroundColor": "rgba(0,0,0,0)",
  "textStyle": {},
  "title": {
    "textStyle": {
      "color": "#516b91"
    },
    "subtextStyle": {
      "color": "#93b7e3"
    }
  },
  "line": {
    "itemStyle": {
      "normal": {
        "borderWidth": "2"
      }
    },
    "lineStyle": {
      "normal": {
        "width": "2"
      }
    },
    "symbolSize": "6",
    "symbol": "emptyCircle",
    "smooth": true
  },
  "radar": {
    "itemStyle": {
      "normal": {
        "borderWidth": "2"
      }
    },
    "lineStyle": {
      "normal": {
        "width": "2"
      }
    },
    "symbolSize": "6",
    "symbol": "emptyCircle",
    "smooth": true
  },
  "bar": {
    "itemStyle": {
      "normal": {
        "barBorderWidth": 0,
        "barBorderColor": "#ccc"
      },
      "emphasis": {
        "barBorderWidth": 0,
        "barBorderColor": "#ccc"
      }
    }
  },
  "pie": {
    "itemStyle": {
      "normal": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      },
      "emphasis": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      }
    }
  },
  "scatter": {
    "itemStyle": {
      "normal": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      },
      "emphasis": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      }
    }
  },
  "boxplot": {
    "itemStyle": {
      "normal": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      },
      "emphasis": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      }
    }
  },
  "parallel": {
    "itemStyle": {
      "normal": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      },
      "emphasis": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      }
    }
  },
  "sankey": {
    "itemStyle": {
      "normal": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      },
      "emphasis": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      }
    }
  },
  "funnel": {
    "itemStyle": {
      "normal": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      },
      "emphasis": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      }
    }
  },
  "gauge": {
    "itemStyle": {
      "normal": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      },
      "emphasis": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      }
    }
  },
  "candlestick": {
    "itemStyle": {
      "normal": {
        "color": "#edafda",
        "color0": "transparent",
        "borderColor": "#d680bc",
        "borderColor0": "#8fd3e8",
        "borderWidth": "2"
      }
    }
  },
  "graph": {
    "itemStyle": {
      "normal": {
        "borderWidth": 0,
        "borderColor": "#ccc"
      }
    },
    "lineStyle": {
      "normal": {
        "width": 1,
        "color": "#aaa"
      }
    },
    "symbolSize": "6",
    "symbol": "emptyCircle",
    "smooth": true,
    "color": [
      "#2d8cf0",
      "#19be6b",
      "#f5ae4a",
      "#9189d5",
      "#56cae2",
      "#cbb0e3"
    ],
    "label": {
      "normal": {
        "textStyle": {
          "color": "#eee"
        }
      }
    }
  },
  "map": {
    "itemStyle": {
      "normal": {
        "areaColor": "#f3f3f3",
        "borderColor": "#516b91",
        "borderWidth": 0.5
      },
      "emphasis": {
        "areaColor": "rgba(165,231,240,1)",
        "borderColor": "#516b91",
        "borderWidth": 1
      }
    },
    "label": {
      "normal": {
        "textStyle": {
          "color": "#000"
        }
      },
      "emphasis": {
        "textStyle": {
          "color": "rgb(81,107,145)"
        }
      }
    }
  },
  "geo": {
    "itemStyle": {
      "normal": {
        "areaColor": "#f3f3f3",
        "borderColor": "#516b91",
        "borderWidth": 0.5
      },
      "emphasis": {
        "areaColor": "rgba(165,231,240,1)",
        "borderColor": "#516b91",
        "borderWidth": 1
      }
    },
    "label": {
      "normal": {
        "textStyle": {
          "color": "#000"
        }
      },
      "emphasis": {
        "textStyle": {
          "color": "rgb(81,107,145)"
        }
      }
    }
  },
  "categoryAxis": {
    "axisLine": {
      "show": true,
      "lineStyle": {
        "color": "#cccccc"
      }
    },
    "axisTick": {
      "show": false,
      "lineStyle": {
        "color": "#333"
      }
    },
    "axisLabel": {
      "show": true,
      "textStyle": {
        "color": "#fff"
      }
    },
    "splitLine": {
      "show": false,
      "lineStyle": {
        "color": [
          "#eeeeee"
        ]
      }
    },
    "splitArea": {
      "show": false,
      "areaStyle": {
        "color": [
          "rgba(250,250,250,0.05)",
          "rgba(200,200,200,0.02)"
        ]
      }
    }
  },
  "valueAxis": {
    "axisLine": {
      "show": true,
      "lineStyle": {
        "color": "#cccccc"
      }
    },
    "axisTick": {
      "show": false,
      "lineStyle": {
        "color": "#333"
      }
    },
    "axisLabel": {
      "show": true,
      "textStyle": {
        "color": "#fff"
      }
    },
    "splitLine": {
      "show": false,
      "lineStyle": {
        "color": [
          "#eeeeee"
        ]
      }
    },
    "splitArea": {
      "show": false,
      "areaStyle": {
        "color": [
          "rgba(250,250,250,0.05)",
          "rgba(200,200,200,0.02)"
        ]
      }
    }
  },
  "logAxis": {
    "axisLine": {
      "show": true,
      "lineStyle": {
        "color": "#cccccc"
      }
    },
    "axisTick": {
      "show": false,
      "lineStyle": {
        "color": "#333"
      }
    },
    "axisLabel": {
      "show": true,
      "textStyle": {
        "color": "#999999"
      }
    },
    "splitLine": {
      "show": true,
      "lineStyle": {
        "color": [
          "#eeeeee"
        ]
      }
    },
    "splitArea": {
      "show": false,
      "areaStyle": {
        "color": [
          "rgba(250,250,250,0.05)",
          "rgba(200,200,200,0.02)"
        ]
      }
    }
  },
  "timeAxis": {
    "axisLine": {
      "show": true,
      "lineStyle": {
        "color": "#cccccc"
      }
    },
    "axisTick": {
      "show": false,
      "lineStyle": {
        "color": "#333"
      }
    },
    "axisLabel": {
      "show": true,
      "textStyle": {
        "color": "#999999"
      }
    },
    "splitLine": {
      "show": true,
      "lineStyle": {
        "color": [
          "#eeeeee"
        ]
      }
    },
    "splitArea": {
      "show": false,
      "areaStyle": {
        "color": [
          "rgba(250,250,250,0.05)",
          "rgba(200,200,200,0.02)"
        ]
      }
    }
  },
  "toolbox": {
    "iconStyle": {
      "normal": {
        "borderColor": "#999"
      },
      "emphasis": {
        "borderColor": "#666"
      }
    }
  },
  "legend": {
    "textStyle": {
      "color": "#fff"
    }
  },
  "tooltip": {
    "axisPointer": {
      "lineStyle": {
        "color": "#ccc",
        "width": 1
      },
      "crossStyle": {
        "color": "#ccc",
        "width": 1
      }
    }
  },
  "timeline": {
    "lineStyle": {
      "color": "#8fd3e8",
      "width": 1
    },
    "itemStyle": {
      "normal": {
        "color": "#8fd3e8",
        "borderWidth": 1
      },
      "emphasis": {
        "color": "#8fd3e8"
      }
    },
    "controlStyle": {
      "normal": {
        "color": "#8fd3e8",
        "borderColor": "#8fd3e8",
        "borderWidth": 0.5
      },
      "emphasis": {
        "color": "#8fd3e8",
        "borderColor": "#8fd3e8",
        "borderWidth": 0.5
      }
    },
    "checkpointStyle": {
      "color": "#8fd3e8",
      "borderColor": "rgba(138,124,168,0.37)"
    },
    "label": {
      "normal": {
        "textStyle": {
          "color": "#8fd3e8"
        }
      },
      "emphasis": {
        "textStyle": {
          "color": "#8fd3e8"
        }
      }
    }
  },
  "visualMap": {
    "color": [
      "#516b91",
      "#59c4e6",
      "#a5e7f0"
    ]
  },
  "dataZoom": {
    "backgroundColor": "rgba(0,0,0,0)",
    "dataBackgroundColor": "rgba(255,255,255,0.3)",
    "fillerColor": "rgba(167,183,204,0.4)",
    "handleColor": "#a7b7cc",
    "handleSize": "100%",
    "textStyle": {
      "color": "#333"
    }
  },
  "markPoint": {
    "label": {
      "normal": {
        "textStyle": {
          "color": "#eee"
        }
      },
      "emphasis": {
        "textStyle": {
          "color": "#eee"
        }
      }
    }
  }
}

  构建完成之后,整体的目录结构如下图所示

在这里插入图片描述

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

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

相关文章

WebRTC中的NAT穿透

NAT简介 我们知道&#xff0c;WebRTC会按照内网、P2P、中转的顺序来尝试连接。在大部分的情况下&#xff0c;实际是使用P2P或者中转的。这里P2P的场景主要使用的技术就是NAT穿透。 我们先简单了解下NAT。NAT在真实网络中是常见的&#xff0c;它的出现一是为了解决ipv4地址不够…

2.1操作系统-进程管理:进程的同步与互斥、信号量与PV操作、PV操作与互斥模型、PV操作与同步模型

2.1操作系统-进程管理&#xff1a;进程的同步与互斥、信号量与PV操作、PV操作与互斥模型、PV操作与同步模型进程的同步与互斥PV操作PV操作与互斥模型PV操作与同步模型进程的同步与互斥 进程是动态的&#xff0c;有一些动态变迁的过程&#xff0c;进程在计算机中是可以同时存在…

JavaEE简单示例——Spring框架的简单介绍

简单介绍&#xff1a; 在我们之前创建的Java项目中&#xff0c;会发现我们的各种类&#xff0c;接口文件和配置文件都放在了一起&#xff0c;虽然我们也做了一些包管理去管理我们的这些文件&#xff0c;但是对于我们来说&#xff0c;这些操作还是太繁琐了&#xff0c;尤其是当…

Spark-RDD创建、并行分区

集合&#xff08;内存&#xff09;中创建 RDD 外部存储&#xff08;文件&#xff09;创建 RDD 并行与分区 分区的设定 集合&#xff08;内存&#xff09;中创建 RDD 从集合中创建 RDD&#xff0c;Spark 主要提供了两个方法&#xff1a;parallelize 和 makeRDD&#xff0c;从…

【源码解析】SpringBoot缓存之@Cacheable的快速入门和源码解析

快速入门 启动类上添加注解EnableCaching在方法上添加注解Cacheable。 OverrideCacheable(cacheNames "value", key "#code_#dictKey")public String getValue(String code, Integer dictKey) {return baseMapper.getValue(code, dictKey);}OverrideCac…

数据结构和算法学习记录——线性表之单链表(上)-初始单链表及其头插函数(顺序表缺陷、单链表优点、链表打印)

单链表的概念单链表是一种链式存取的数据结构&#xff0c;链表中的数据是以结点来表示的。每个结点的构成&#xff1a;元素(数据元素的映象) 指针(指示后继元素存储位置)。元素就是存储数据的存储单元&#xff0c;指针就是连接每个结点的地址数据。以“结点的序列”表示的线性…

Kubernetes Service简介

Service 之前我们了解了Pod的基本用法&#xff0c;我们也了解到Pod的生命是有限的&#xff0c;死亡过后不会复活了。我们后面学习到的RC和Deployment可以用来动态的创建和销毁Pod。尽管每个Pod都有自己的IP地址&#xff0c;但是如果Pod重新启动了的话那么他的IP很有可能也就变…

cocos2dx+lua学习笔记:事件派发器CCEventDispatcher

前言 本篇在讲什么 cocos2dx内关于事件监听和派发的调度器EventDispatcher相关内容 本篇适合什么 适合初学Cocos2dx的小白 适合想要学习EventDispatcher的新手 本篇需要什么 对Lua语法有简单认知 对C语法有简单认知 对Cocos2dx有简单认知 Cocos2dx-Lua的开发环境 依…

【Spring事物三千问】DataSource的设计和常用实现——Hikari、Druid

javax.sql.DataSource javax.sql.DataSource 是 jdk 提供的接口&#xff0c;各个连接池厂商 和 Spring 都对 DataSource 进行了设计和实现。 javax.sql.DataSource 是连接到物理数据源的工厂接口。它是 java.sql.DriverManager 功能的替代者&#xff0c;是获取数据库连接的首选…

H5视频付费点播打赏影视系统程序全开源运营版,含完整的前后台+数据库

源码介绍&#xff1a; 这是一个非常棒的精品代码&#xff0c;之前官方网站售价可是超过2w的。我拿过来了简单测试了一下&#xff0c;完美。好久没有遇到这么好的代码了&#xff0c;特此整理了一份完整的搭建教程并分享一下。 thinkphp开发&#xff0c;前后端分离设计&#xf…

Vue3做出B站【bilibili】 Vue3+TypeScript+ant-design-vue【快速入门一篇文章精通系列(一)前端项目案例】

本项目分为二部分 1、后台管理系统&#xff08;用户管理&#xff0c;角色管理&#xff0c;视频管理等&#xff09; 2、客户端&#xff08;登录注册、发布视频&#xff09; Vue3做出B站【bilibili】 Vue3TypeScriptant-design-vue【快速入门一篇文章精通系列&#xff08;一&…

ASEMI高压MOS管20N60参数,20N60尺寸,20N60体积

编辑-Z ASEMI高压MOS管20N60参数&#xff1a; 型号&#xff1a;20N60 漏极-源极电压&#xff08;VDS&#xff09;&#xff1a;600V 栅源电压&#xff08;VGS&#xff09;&#xff1a;30V 漏极电流&#xff08;ID&#xff09;&#xff1a;20A 功耗&#xff08;PD&#xff…

项目最后一刻发生范围变更该怎么处理?

不管是项目需求发生了变化&#xff0c;还是第一轮可交付成果没有完全达到预期&#xff0c;在项目范围定义的初始阶段之后可能发生变化的原因有很多。当这种情况发生时&#xff0c;你需要准备好一个计划来处理最后一刻的范围变更和调整。 什么是范围变更&#xff1f; 范围变更是…

浪潮 KaiwuDB x 山东重工 | 打造离散制造业 IIoT 标杆解决方案

近日&#xff0c;浪潮 KaiwuDB 携手山东重工集团有限公司&#xff08;以下简称&#xff1a;山东重工&#xff09;重磅发布“离散制造业 IIoT 解决方案”。该 IIoT 方案以 KaiwuDB 就地运算专利技术为底座&#xff0c;搭建了”多快优智”的“13N”方案体系&#xff0c;目前已率先…

南京、西安集成电路企业和高校分布一览(附产业链主要厂商及高校名录)

前言 3月2日&#xff0c;国务院副总理刘鹤在北京调研集成电路企业发展&#xff0c;并主持召开座谈会。刘鹤指出&#xff0c;集成电路是现代化产业体系的核心枢纽&#xff0c;关系国家安全和中国式现代化进程。他表示&#xff0c;我国已形成较完整的集成电路产业链&#xff0c;也…

视频理解论文串讲——学习笔记

文章目录DeepVideoTwo-StreamBeyond-short-SmippetsConvolutional FusionTSNC3DI3DNon-localR&#xff08;21&#xff09;DSlowFastTimesformer本文是对视频理解领域论文串讲的笔记记录。 一篇相关综述&#xff1a;Yi Zhu, Xinyu Li, Chunhui Liu, Mohammadreza Zolfaghari, Yu…

【YOLO】YOLOv8训练自定义数据集

1. 运行环境 windows11 和 Ubuntu20.04&#xff08;建议使用 Linux 系统&#xff09; 首先切换到自己建立的虚拟环境安装 pytorch torch 1.12.0cu116&#xff08;根据自身设备而定&#xff09; torchvision 0.13.0cu116&#xff08;根据自身设备而定&…

详解JAVA枚举类

目录 1.概述 2.常用API 2.1.清单 2.2.代码示例 2.2.1.ordinal 2.2.2.compareTo 2.2.3.toString 2.2.4.valueOf 2.2.5.values 3.成员变量和带参构造 1.概述 枚举变量指的是变量的取值只在一个有限的集合内&#xff0c;如性别、星期几、颜色等。从JDK5开始&#xff0…

超详细CentOS7 NAT模式(有图形化界面)网络配置

在此附上CentOS7&#xff08;有可视化界面版&#xff09;安装教程 超详细VMware CentOS7&#xff08;有可视化界面版&#xff09;安装教程 打开VMware—>点击编辑---->选择虚拟网络编辑器 打开虚拟网络编辑器后如下图所示&#xff1a; 从下图中我们看到最下面子网IP为…

软测入门(九)unit test

unit test 核心概念 TestCase:测试用例&#xff1a;用类的方式 组织对一个功能的多项测试Fixture : 夹具&#xff0c;用来固定测试环境TestSuite:测试套件:组织多个TestCaseTestRunner:测试执行:用来执行TestSuit&#xff0c;可以导出测试结果 入门 类需要继承unittest.Tes…