vue3 + ts + echart 实现柱形图表

首先封装Echart一个文件   代码如下

<script setup lang="ts">
import { ECharts, EChartsOption, init } from 'echarts';
import { ref, watch, onMounted, onBeforeUnmount } from 'vue';// 定义props
interface Props {width?: string;height?: string;option: EChartsOption;
}
const props = withDefaults(defineProps<Props>(), {width: '100%',height: '100%',option: () => ({})
});const myChartsRef = ref<HTMLDivElement>();
let myChart: ECharts;
// eslint-disable-next-line no-undef
let timer: string | number | NodeJS.Timeout | undefined;// 初始化echarts
const initChart = (): void => {if (myChart !== undefined) {myChart.dispose();}myChart = init(myChartsRef.value as HTMLDivElement);// 拿到option配置项,渲染echartsmyChart?.setOption(props.option, true);
};// 重新渲染echarts
const resizeChart = (): void => {timer = setTimeout(() => {if (myChart) {myChart.resize();}}, 500);
};onMounted(() => {initChart();window.addEventListener('resize', resizeChart);
});onBeforeUnmount(() => {window.removeEventListener('resize', resizeChart);clearTimeout(timer);timer = 0;
});watch(props.option,() => {initChart();},{deep: true}
);
</script>
<template><div ref="myChartsRef" :style="{ height: height, width: width }" :option="option" />
</template>

第一一个案例代码如下    需要引入我们封装好的  Echart.vue文件

<script setup lang="ts">
import { reactive } from 'vue';
import Echarts from './index.vue';const option = reactive({tooltip: {trigger: 'axis',axisPointer: {type: 'shadow',label: {show: true}}},grid: {left: '6%',top: '15%',right: '0',bottom: '10%'},legend: {data: ['昨日总人数', '今日实时人数'],top: '0',color: '#4ADEFE',fontSize: 14,selected: { 昨日使用率: false }, // 不需要显示的设置为falsetextStyle: {color:'#4ADEFE',},x : 'right',y : 'top',},xAxis: {data: ['会议室1','会议室2','会议室3','会议室4','会议室5','会议室6','会议室7','会议室8','会议室9'],axisLine: {show: true, //隐藏X轴轴线lineStyle: {color: '#4ADEFE',width: 1}},axisTick: {show: true, //隐藏X轴刻度alignWithLabel: true},axisLabel: {show: true,color: '#4ADEFE', //X轴文字颜色fontSize: 12}},yAxis: [{type: 'value',name: '人数',nameTextStyle: {color: '#4ADEFE',fontSize: 12},splitLine: {show: true,lineStyle: {width: 1,color: '#4ADEFE'}},axisTick: {show: false},axisLine: {show: false},axisLabel: {show: true,color: '#4ADEFE',fontSize: 12}}],series: [{name: '昨日总人数',type: 'bar',barWidth: 10,itemStyle: {color: {type: 'linear',x: 0, // 右y: 1, // 下x2: 0, // 左y2: 0, // 上colorStops: [{offset: 0,color: '#f3db5c' // 0% 处的颜色},{offset: 1,color: '#f3db5c' // 100% 处的颜色}]}},data: [240, 145, 43, 35, 76, 154, 360, 42, 168]},{name: '今日实时人数',type: 'bar',barWidth: 10,itemStyle: {color: {type: 'linear',x: 0, // 右y: 1, // 下x2: 0, // 左y2: 0, // 上colorStops: [{offset: 0,color: '#4adefe' // 0% 处的颜色},{offset: 1,color: '#4adefe' // 100% 处的颜色}]}},data: [133, 23, 114, 67, 89, 35, 67, 96, 90]}]
});
</script><template><div :style="{ width: '100%', height: '90%' }"><Echarts :option="option" /></div>
</template>

第二个案例同上

<script setup lang="ts">
import { reactive } from 'vue';
import Echarts from './index.vue';const data = {"orderNum":["39","77","96","41","24","17","0","10"],"categoryArr":["订购附属","新装","拆机","改客户资料","补换卡","过户","换挡","移机"],"avgTime":["10.79","17.05","14.84","10.07","5.58","10.36","0.00","4.43"],"legendArr":["耗时时间","订单量"]
}
let maxOrder=Math.max.apply(null,data.orderNum);
const option = reactive({title : {text:'',subtext:'',top:'3',right:'0'},tooltip: {trigger: 'axis'},grid: {left: '8%',right: '8%',bottom: '10%'},xAxis: {type: 'category',axisLine: {lineStyle: {color: '#57617B'}},axisLabel: {interval:0,textStyle: {color:'#fff',}},data: data.categoryArr},yAxis:[{type: 'value',name: '',axisLine: {lineStyle: {color: '#57617B'}},axisLabel: {margin: 10,textStyle: {fontSize: 12},textStyle: {color:'#fff'},formatter:'{value}分'},splitLine: {show: false}},{type: 'value',name: '',max:maxOrder+parseInt(maxOrder*0.2),axisLabel: {margin: 10,textStyle: {fontSize: 12},textStyle: {color:'#fff'},formatter:'{value}笔'},splitLine: {show: true,lineStyle:{type:'dashed',color: ['#25CEF3']}}}],series: [{name:'耗时时间',type:'line',yAxisIndex:0,smooth: false,symbolSize:5,lineStyle: { normal: {width: 2}},areaStyle: {normal: {color: {type: 'linear',x: 0,y: 0,x2: 0,y2: 1,colorStops: [{offset: 0,color: 'rgba(230, 48, 123, 0.8)'},{offset: 0.8,color: 'rgba(230, 48, 123, 0)'}],globalCoord: false // 缺省为 false},shadowColor: 'rgba(0, 0, 0, 0.1)',shadowBlur: 10}},itemStyle: {normal: { color: '#DA2F78'}},data:data.avgTime},{name:'订单量',type:'bar',barWidth:12,yAxisIndex:1,itemStyle : {normal: {barBorderRadius:[10, 10, 0, 0],color: {type: 'linear',x: 0,y: 1,x2: 0,y2: 0,colorStops: [{offset: 0,color: "#4033F9"},{offset: 0.8,color: "#BA97F9"}],globalCoord: false // 缺省为 false},shadowColor: 'rgba(0, 0, 0, 0.1)',}},data:data.orderNum}]
});
</script><template><div :style="{ width: '100%', height: '90%' }"><Echarts :option="option" /></div>
</template>

更多案例可以查看我的个人网站   会持续更新  相关案例   人间且慢行 | 前端网站大全 | web前端开发

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

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

相关文章

pclpy 窗口可视化多个点云

pclpy 窗口可视化多个点云 一、算法原理二、代码三、结果1.可视化结果 四、相关数据五、问题与解决方案1.问题2.解决 一、算法原理 原理看一下代码写的很仔细的。。目前在同一个窗口最多可视化两个点云。。 二、代码 from pclpy import pcldef CloudShow(cloud1, cloud2):&q…

04 动力云客之登录后获取用户信息+JWT存进Redis+Filter验证Token + token续期

1. 登录后获取用户信息 非常好实现. 只要新建一个controller, 并调用SS提供的Authentication对象即可 package com.sunsplanter.controller;RestController public class UserController {GetMapping(value "api/login/info")public R loginInfo(Authentication a…

C++ 基础算法 双指针 数组元素的目标和

给定两个升序排序的有序数组 A 和 B &#xff0c;以及一个目标值 x 。 数组下标从 0 开始。 请你求出满足 A[i]B[j]x 的数对 (i,j) 。 数据保证有唯一解。 输入格式 第一行包含三个整数 n,m,x &#xff0c;分别表示 A 的长度&#xff0c;B 的长度以及目标值 x 。 第二行包…

使用静态CRLSP配置MPLS TE隧道

正文共&#xff1a;1591 字 13 图&#xff0c;预估阅读时间&#xff1a;4 分钟 静态CRLSP&#xff08;Constraint-based Routed Label Switched Paths&#xff0c;基于约束路由的LSP&#xff09;是指在报文经过的每一跳设备上&#xff08;包括Ingress、Transit和Egress&#xf…

C语言内存模型的深度剖析

一、C语言内存模型的详细构成 在计算机体系结构中&#xff0c;内存被抽象为一个线性的地址空间&#xff0c;C语言内存模型即建立在此基础之上。每个存储单元都有一个唯一的地址&#xff0c;这个地址空间从0开始递增&#xff0c;范围受限于处理器架构和操作系统提供的物理或虚拟…

Ubuntu18.4桌面版安装并配置apt update与远程访问

1、无脑直接一步步安装即可 2、安装完成后与服务器版不同的是 服务器版(参照系统安装博客)通过选项安装openssh,桌面版啊需要通过 apt install openssh-server 进行安装 ----小插曲--- 如果使用apt install openssh-server 时 报错 无法解析ip 那么是由于未配置DNS 配置为1…

使用alist连接百度网盘和阿里云盘挂载到本地磁盘

1、下载alist软件 alist软件下载地址&#xff1a;https://github.com/alist-org/alist 跳转后&#xff0c;找到对应的windows版本 2 、下载后解压&#xff0c;并启动服务 注意&#xff1a;alist的启动方式不是传统的双击启动&#xff0c;需要用命令提示符,启动服务 下载完成…

平时积累的FPGA知识点(9)

平时在FPGA群聊等积累的FPGA知识点&#xff0c;第9期&#xff1a; 31 ldpc的license是什么&#xff1f; 解释&#xff1a;Xilinx公司的Zynq UltraScale RFSoC系列芯片进行项目开发&#xff0c;在某些芯片型号中&#xff0c;自身带有SD-FEC硬核资源&#xff0c;具体查询方式&a…

Aster实现一台电脑当两台使——副屏搭配键鼠

前言&#xff1a;笔者每年回家&#xff0c;都面临着想要和小伙伴一起玩游戏&#xff0c;但小伙伴没有电脑/只有低配电脑的问题。与此同时&#xff0c;笔者自身的电脑是高配置的电脑&#xff0c;因此笔者想到&#xff0c;能否在自己的电脑上运行游戏&#xff0c;在小伙伴的电脑上…

MKS T3BI集成蝶阀说明T3B-T3PRS-232Supplement

MKS T3BI集成蝶阀说明T3B-T3PRS-232Supplement

力扣(leetcode)第455题分发饼干(Python)

455.分发饼干 题目链接:455.分发饼干 假设你是一位很棒的家长,想要给你的孩子们一些小饼干。但是,每个孩子最多只能给一块饼干。 对每个孩子 i,都有一个胃口值 g[i],这是能让孩子们满足胃口的饼干的最小尺寸;并且每块饼干 j,都有一个尺寸 s[j] 。如果 s[j] >= g[i…

Vue自定义指令的三个方法

目录 ​编辑 介绍 创建方法&#xff1a; min.js注册 script setup中使用 script中使用&#xff1a; 指令钩子 钩子参数 简化形式 对象字面量 在组件上使用 介绍 除了 Vue 内置的一系列指令 (比如 v-model 或 v-show) 之外&#xff0c;Vue 还允许你注册自定义的指令…

在c++11 的unordered_set和unordered_map中插入pair或tuple作为键值

参考:https://blog.csdn.net/pineappleKID/article/details/108341064 想完成的任务 与 遇到的问题 想在c11 的unordered_set和unordered_map中插入pair或tuple作为键值 std::unordered_map<std::pair<std::string,std::string>, int> m;会报错 /usr/include/c/4…

GB/T 43564-2018 中小学合成材料面层田径场地检测

合成材料面层是指铺装在沥青混凝土或水泥混凝土等基础层上的高分子合成材料层&#xff0c;按照使用功能分为田径产地&#xff0c;球类场地和其他活动场地&#xff0c;按照材料形态分为现浇型面层、预制型面层和人造草面层。 GB/T 43564-2018中小学合成材料面层田径场地检测项目…

Codeforces Round 927 (Div. 3) LR-remainders的题解

原题描述&#xff1a; C.LR-remains 每次测试时限&#xff1a;2 秒 每次测试的内存限制&#xff1a;256 兆字节 输入&#xff1a;标准输入 输出&#xff1a;标准输出 样例1输入&#xff1a; 4 4 6 3 1 4 2 LRRL 5 1 1 1 1 1 1 LLLLL 6 8 1 2 3 4 5 6 RLLLRR 1 10000 1000…

MySQL初识——安装配置

文章目录 1. MySQL卸载2. 获取MySQL官方yum源安装包3. 安装4. 启动MySQL5. 登录6. 配置配置文件 Tips&#xff1a; 本章是Centos 7安装配置myql&#xff0c;配置操作用的是root权限 1. MySQL卸载 首先我们先查看一下系统中是否有mysql服务 ps axj | grep mysql如果有&#xf…

java 写入写出 zip

package com.su.test.aaaTest.ioTest; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; /** 将文件压缩到 zip 中 */ public c…

项目中遇到的跨域问题两种解决方式

第一种跨域解决方式 第一种就是我们平常使用的解决跨域问题的方法&#xff0c;但是要实现WebMvcConfigurer 接口&#xff0c;还需要导入web依赖&#xff0c;如果我们不引入web依赖&#xff0c;如何解决跨域呢&#xff1f; 答&#xff1a;看第二种方式 pom.xml <dependenc…

Vue2路由组件练习

Vue2路由组件练习 1. 演示效果 2. 代码分析 2.1. 安装 vue-router 命令&#xff1a;npm i vue-router 应用插件&#xff1a;Vue.use(VueRouter) 2.2. 创建路由文件 在 src 文件夹下&#xff0c;创建router文件夹&#xff0c;并在该文件夹创建index.js文件 2.3. 导入依赖…

K8S实战:Centos7部署Kubernetes1.20.0集群

目录 一、准备工作1.1、创建3台虚拟机1.1.1、下载虚拟机管理工具1.1.2、安装虚拟机管理工具1.1.3、下载虚Centos镜像1.1.4、创建3台虚拟机1.1.5、设置虚拟机网络环境 1.2、虚拟机基础配置&#xff08;3台虚拟机进行相同处理&#xff09;1.2.1、配置host1.2.2、关闭防火墙1.2.3、…