echarts 甘特图一组显示多组数据

 

<template><el-button type="primary" @click="addlin">添加线</el-button><el-button type="success" @click="addArea">添加区域</el-button><div ref="echart" id="echart" class="echart"></div>
</template><script setup>
import { nextTick, onMounted, ref } from "vue";
import * as echarts from "echarts";
let colorTheme = ["#4150d8","#28bf7e","#ed7c2f","#ff0000","#f9cf36","#4a5bdc","#7b04f4","#ee04f4","#04a0f4","#1af404","#d4f404","#f404f1",
];
// 0 代表y轴索引   后面0 代表 甘特图一个数据有多行  0 代表1个 1 代表2个
// [0, "2021-07-19 03:29:19", "2021-07-19 08:38:50", 0]
let showData = [[{value: [0, "2021-07-19 03:29:19", "2021-07-19 08:38:50", 0],},{value: [1, "2021-07-19 03:53:07", "2021-07-19 21:00:08", 1],},{value: [2, "2021-07-19 03:29:19", "2021-07-19 08:38:50", 0],},],[{value: [0, "2021-07-19 00:00:00", "2021-07-19 05:08:02", 0],},{value: [1, "2021-07-19 00:00:00", "2021-07-19 05:08:02", 0],},{value: [2, "2021-07-19 00:00:00", "2021-07-19 05:08:02", 0],},],[{value: [0, "2021-07-19 00:00:00", "2021-07-19 05:08:02", 2],},{value: [1, "2021-07-19 00:00:00", "2021-07-19 05:08:02", 2],},{value: [2, "2021-07-19 00:00:00", "2021-07-19 05:08:02", 2],},],[{value: [0, "2021-07-19 10:00:00", "2021-07-19 15:08:02", 3],},{value: [1, "2021-07-19 10:00:00", "2021-07-19 15:08:02", 3],},{value: [2, "2021-07-19 10:00:00", "2021-07-19 15:08:02", 3],},],[{value: [0, "2021-07-19 10:00:00", "2021-07-19 15:08:02", 4],},{value: [1, "2021-07-19 10:00:00", "2021-07-19 15:08:02", 4],},{value: [2, "2021-07-19 10:00:00", "2021-07-19 15:08:02", 4],},],
];let linflag = false;
const addlin = () => {linflag = !linflag;option.series = option.series.map((item) => {item.markLine = {data: [],};return item;});if (linflag) {option.series[0].markLine = {//使用警戒线symbol: "none", //取消警戒线箭头silent: "true", //图形是否不响应和触发鼠标事件,默认为 false,即响应和触发鼠标事件data: [{ xAxis: "2021-07-19 10:53:07" }],label: {show: true,color: "red",fontSize: 20,formatter: "",},lineStyle: {//线条颜色与线条虚实color: colorTheme[0], //航线的颜色type: "scrollDataIndex",},};}myChart.setOption(option);
};let areaflag = false;
const addArea = () => {areaflag = !areaflag;option.series = option.series.map((item) => {item.markArea = {data: [],};return item;});if (areaflag) {option.series[0].markArea = {itemStyle: {color: "rgba(0,0,0,0.2)",},data: [[{ xAxis: "2021-07-19 03:29:19" },{ xAxis: "2021-07-19 08:29:19" },],],};}myChart.setOption(option);
};
// 分配y值
const produceSeries = (data) => {let len = data.length;let step = len % 2 == 1 ? -5 : 2;let series = [];data.map((val, index) => {if (step == -5) {series.push(configSeriec(val, index, 0));step = step + 30;return;}if (index % 2 == 0) {series.push(configSeriec(val, index, step));step = step + 20;} else {series.push(configSeriec(val, index, -step));step = step + 10;}});function configSeriec(val, index, step) {return {type: "custom",renderItem: (params, api) => {//开发者自定义的图形元素渲染逻辑,是通过书写 renderItem 函数实现的var categoryIndex = api.value(0); //这里使用 api.value(0) 取出当前 dataItem 中第一个维度的数值。var start = api.coord([api.value(1), categoryIndex]); // 这里使用 api.coord(...) 将数值在当前坐标系中转换成为屏幕上的点的像素值。var end = api.coord([api.value(2), categoryIndex]);var height = 10;return {type: "rect", // 表示这个图形元素是矩形。还可以是 'circle', 'sector', 'polygon' 等等。y: step,shape: echarts.graphic.clipRectByRect({// 矩形的位置和大小。x: start[0],y: start[1] - height / 2,width: end[0] - start[0],height: height,},{// 当前坐标系的包围盒。x: params.coordSys.x,y: params.coordSys.y,width: params.coordSys.width,height: params.coordSys.height,}),style: api.style(),};},encode: {x: [1, 2], // data 中『维度1』和『维度2』对应到 X 轴y: 0, // data 中『维度0』对应到 Y 轴},itemStyle: {normal: {color: function (params) {//return colorTheme[params.value[0]];return colorTheme[index];},},},data: val,};}return series;
};let option = {// grid: {//     left: "5%",//     right: "7%",//     bottom: "5%",//     containLabel: false,// },title: {text: "我是标题",top: "1%",x: "center",textStyle: {fontSize: 20,color: "#333333",},},tooltip: {enterable: true,backgroundColor: "rgba(255,255,255,1)", //背景颜色(此时为默认色)borderRadius: 5, //边框圆角padding: 10, // [5, 10, 15, 20] 内边距textStyle: {color: "#000",},position: function (point, params, dom, rect, size) {dom.innerHTML = params.value[1] + "~" + params.value[2];},},legend: {//图例data: "我是图例",left: "90px",top: 22,itemWidth: 16,itemHeight: 16,selectedMode: false, // 图例设为不可点击textStyle: {color: "#333333",fontSize: 16,},},toolbox: {show: true,feature: {saveAsImage: {},},},xAxis: {name: "场景时间",nameTextStyle: {color: "#333333",fontSize: 18,},type: "time",splitNumber: 6,max: "2021-07-20 00:00:00",min: "2021-07-19 00:00:00", //将data里最小时间的整点时间设为min,否则min会以data里面的min为开始进行整点递增axisLabel: {show: true,formatter: function (value) {//在这里写你需要的时间格式var t_date = new Date(value);return ([t_date.getFullYear(),t_date.getMonth() + 1,t_date.getDate(),].join("-") +" " +[t_date.getHours(), t_date.getMinutes()].join(":"));},},splitLine: {show: true,lineStyle: {color: "#333333",},},axisLine: {show: true,color: "#333333",symbol: ["none", "arrow"],lineStyle: {color: "#333333",width: 1,type: "solid",},},},yAxis: {name: "y轴",nameTextStyle: {color: "#333333",fontSize: 18,},axisLine: {color: "#333333",lineStyle: {color: "#333333",},symbol: ["none", "arrow"],},axisLabel: {show: true,textStyle: {color: "#333333", //这里用参数代替了},},data: ["示例1", "示例2", "示例3"],},dataZoom: [{show: true,realtime: true,start: 0,end: 100,height: 20,borderColor: "rgba(43,48,67,0.5)",fillerColor: "#269cdb", //滑动块的颜色backgroundColor: "rgba(44, 92, 170, 0.35)", //两边未选中的滑动条区域的颜色xAxisIndex: [0, 1],width: "86%",},{type: "inside",realtime: true,start: 30,end: 70,// xAxisIndex: [0, 1],},{type: "slider",show: true,// 设置组件控制的y轴yAxisIndex: 0,right: 15,// top: 60,// 数据窗口范围的起始百分比。范围是:0 ~ 100。表示 0% ~ 100%// 也可以用 startValue设置起始值// start: "0",// end: "50",maxSpan: 20,maxValueSpan: 3, // 最大显示y轴的条数width: 20, //滚动条的粗细// height: 450,// 组件的背景颜色// left: 600, //左边的距离// right: 8,//右边的距离borderRadius: 8,borderColor: "rgba(43,48,67,0.5)",fillerColor: "#269cdb", //滑动块的颜色backgroundColor: "rgba(44, 92, 170, 0.35)", //两边未选中的滑动条区域的颜色// 是否显示detail,即拖拽时候显示详细数值信息showDetail: false,// 控制手柄的尺寸handleSize: 16,// 是否在 dataZoom-silder 组件中显示数据阴影。数据阴影可以简单地反应数据走势。showDataShadow: false,zoomLock: true, //禁止拖拽   y轴固定,不能拉长滚动条},{type: "inside",yAxisIndex: [0],start: 1,end: 36,// 鼠标滚轮Y轴能触发缩放  false  禁止滚轮缩放   true  滚轮可以缩放zoomOnMouseWheel: false,// 不按任何功能键,鼠标移动能触发数据窗口平移},],series: produceSeries(showData),
};let echart = ref();
let myChart;
onMounted(() => {nextTick(() => {console.log(echart.value);myChart = echarts.init(echart.value);myChart.setOption(option);});
});
</script>
<style  lang="less">
.echart {width: 100%;height: 1000px;
}
</style>

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

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

相关文章

应急物资管理系统|智物资DW-S300提升应急响应能力

项目背景 智慧应急物资管理系统&#xff08;智装备DW-S300&#xff09;是一套成熟系统&#xff0c;依托互3D技术、云计算、大数据、RFID技术、数据库技术、AI、视频分析技术对RFID智能仓库进行统一管理、分析的信息化、智能化、规范化的系统。 本项目采用东识智慧应急物资管理…

(三)行为模式:6、备忘录模式(Memento Pattern)(C++示例)

目录 1、备忘录模式&#xff08;Memento Pattern&#xff09;含义 2、备忘录模式的UML图学习 3、备忘录模式的应用场景 4、备忘录模式的优缺点 &#xff08;1&#xff09;优点&#xff1a; &#xff08;2&#xff09;缺点 5、C实现备忘录模式的实例 1、备忘录模式&#…

javaee spring 自动注入,如果满足条件的类有多个如何区别

如图IDrinkDao有两个实现类 方法一 方法二 Resource(name“对象名”) Resource(name"oracleDrinkDao") private IDrinkDao drinkDao;

C# task多线程创建,暂停,继续,结束使用

1、多线程任务创建 private void button1_Click(object sender, EventArgs e) //创建线程{CancellationToken cancellationToken tokensource.Token;Task.Run(() > //模拟耗时任务{for (int i 0; i < 100; i){if (cancellationToken.IsCancellationRequested){return;…

【C语言】每日一题(除自身以外数组的乘积)

添加链接描述&#xff0c;链接奉上 方法&#xff1a; 暴力循环:前缀积后缀积&#xff08;分组&#xff09;: 暴力循环: 暴力循换真的是差生法宝&#xff0c;简单好懂&#xff0c;就是不实用&#xff0c;大多数的题目都会超过时间限制&#xff08;无奈&#xff09; 思路&…

iOS开发Swift-2-图片视图、App图标-赏月App

1.创建新项目 点击File - New - Project。 选择Single View App&#xff0c;点击Next。 填写文件信息&#xff0c;点击Next。 选择文件位置&#xff0c;点击Create。 修改App显示名称为 “赏月”。 2.设置背景色 选择Main&#xff0c;点击View界面&#xff0c;选择右边属性&…

OLAP学习

OLAP又叫联机分析处理&#xff0c;联机分析处理(OLAP)的概念最早是由关系数据库之父E.F.Codd于1993年提出的。 当今的数据处理大致可以分成两大类&#xff1a;联机事务处理OLTP&#xff08;on-linetransactionprocessing&#xff09;、联机分析处理OLAP&#xff08;On-LineAna…

VS的调试技巧

Visual Studiohttps://visualstudio.microsoft.com/zh-hans/vs/ 目录 1、什么是调试&#xff1f; 2、debug和release 3、调试 3.1、环境 3.2、 快捷键 3.2.1、F10和F11 3.2.2、ctrlF5 3.2.3、F5与F9 3.2.3.1、条件断点 3.3、监视和内存观察 3.3.1、监视 3.3.2、内存 …

DSP_TMS320F28377D_算法加速方法2_添加浮点运算快速补充库rts2800_fpu32_fast_supplement.lib

继上一篇博客DSP_TMS320F28377D_算法加速方法1_拷贝程序到RAM运行_江湖上都叫我秋博的博客-CSDN博客之后&#xff0c;本文讲第二种DSP算法加速的方法&#xff0c;该方法的加速效果很明显&#xff0c;但是加速范围仅限于32位浮点数下面这几种函数: 1 工程师的关注点 下面稍微解…

爬虫实战之使用 Python 的 Scrapy 库开发网络爬虫详解

关键词 - Python, Scrapy, 网络爬虫 在信息爆炸时代&#xff0c;我们每天都要面对海量的数据和信息。有时候我们需要从互联网上获取特定的数据来进行分析和应用。今天我将向大家介绍如何使用 Python 的 Scrapy 库进行网络爬虫&#xff0c;获取所需数据。 1. Scrapy 简介 1.1 …

设计模式--装饰者模式(Decorator Pattern)

一、什么是装饰者模式&#xff08;Decorator Pattern&#xff09; 装饰者模式&#xff08;Decorator Pattern&#xff09;是一种结构型设计模式&#xff0c;它允许你在不修改现有对象的情况下&#xff0c;动态地将新功能附加到对象上。这种模式通过创建一个包装类&#xff0c;…

Mysql45讲学习笔记

前言&#xff1a;这篇文章主要总结事务&#xff0c;锁、索引的一些知识点&#xff0c;然后分享一下自己学习小心得&#xff0c;我会从点到线在到面展开说说&#xff0c;对于学习任何知识&#xff0c;我们都应该藐其全貌&#xff0c;不要一开始就选入细节 基础 一、基础架构&a…