当前位置: 首页 > news >正文

echarts之折线柱状图

echarts实现折线柱状图

echarts中文官网:https://echarts.apache.org/examples/zh/index.html

效果图如下:
在这里插入图片描述
整体代码如下(注释很详细):

<template><div id="lineColumnarChart" style="width:100%;height:400px;"></div>
</template><script setup lang="ts">
import * as echarts from "echarts";
import { onMounted } from "vue";// 横坐标data数据
const xData = ["05-01","05-02","05-03","05-04","05-05","05-06","05-07","05-08","05-09","05-10","05-11","05-12","05-13","05-14","05-15","05-16","05-17","05-18","05-19","05-20",
];// 折线柱状图data数据
const lineColumnarData = [[48, 65, 24, 39, 67, 48, 65, 24, 39, 67, 48, 65, 24, 39, 67, 48, 65, 24, 39,67,],[32, 19, 72, 63, 51, 32, 19, 72, 63, 51, 32, 19, 72, 63, 51, 32, 19, 72, 63,41,],[60, 75, 32, 53, 26, 60, 75, 32, 53, 26, 60, 75, 32, 53, 26, 60, 75, 32, 53,26,],[32, 19, 72, 63, 51, 32, 19, 72, 63, 51, 32, 19, 72, 63, 51, 32, 19, 72, 63,51,],
];onMounted(() => {const myLineColumnarChart = echarts.init(document.getElementById("lineColumnarChart"));const lineColumnarOption = {tooltip: {trigger: "axis",backgroundColor: "rgba(7,18,26, 1)",borderWidth: 0,textStyle: {color: "#fff",fontSize: 14,},axisPointer: {lineStyle: {color: "rgba(69, 173, 175, 1)",},},},// 图例组件legend: {icon: "rect",show: true, // 是否显示图例orient: "horizontal", // 图例的朝向    vertical-垂直显示  horizontal-水平显示data: ["尖", "峰", "平", "谷"],itemWidth: 8,itemHeight: 8,itemGap: 15, // 间隔left: "50%", // x轴方向取值 left/center/right  具体像素值或百分比top: 24, // y轴方向取值 top/center/bottomtextStyle: {// 设置图例文字样式color: "#fff",fontSize: 12,},},// 上下左右及大小-设置图表占总面积的地方grid: {left: "4%", //左侧 y轴内容距离边框的距离(类似padding-left)top: "27%", // 与容器顶部的距离right: "1%",bottom: "12%", // 与容器底部的距离},// grid坐标系的x轴xAxis: [{type: "category",data: xData,axisPointer: {type: "shadow",},axisTick: {show: false, // 不显示坐标轴刻度线},// show: false, // 不显示坐标轴线、坐标轴刻度线和坐标轴上的文字// axisTick: {// 	show: false // 不显示坐标轴刻度线// },axisLine: {lineStyle: {color: "#415264",width: 2,type: "solid",},},axisLabel: {color: "#A6C6E1",fontSize: 12,},// splitLine: {// 	show: false // 不显示网格线// }},],// grid坐标系的y轴yAxis: [{type: "value",axisTick: {show: false,},axisLine: {lineStyle: {color: "#284556",},},splitLine: {//分割线配置show: true,lineStyle: {color: "#284556",type: "dashed",},},axisLabel: {// formatter: "{value}",color: "#9FA3A8",fontSize: 12,},},{type: "value",show: false,},],// 系列列表。每个系列通过 type 决定自己的图表类型series: [{name: "尖",type: "bar",itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{//代表渐变色从正上方开始offset: 0, //offset范围是0~1,用于表示位置,0是指0%处的颜色color: "#042230",}, //柱图渐变色{offset: 1, //指100%处的颜色color: "#45B1BD",},]),barBorderRadius: [2, 2, 0, 0],},},tooltip: {valueFormatter: function (value: any) {return value;},},data: lineColumnarData[0],},{name: "峰",type: "bar",itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{//代表渐变色从正上方开始offset: 0, //offset范围是0~1,用于表示位置,0是指0%处的颜色color: "#042231",}, //柱图渐变色{offset: 1, //指100%处的颜色color: "#09B1F7",},]),barBorderRadius: [2, 2, 0, 0],},},tooltip: {valueFormatter: function (value: any) {return value;},},data: lineColumnarData[1],},{name: "平",type: "line",lineStyle: {width: 1, // 设置线条宽度为5},symbol: "circle", // 设置为圆形symbolSize: 5, // 设置圆形的大小color: "#FFA668", //颜色itemStyle: {color: "#FFA668", // 设置圆形的填充颜色borderColor: "rgba(255,166,104, 0.4)", // 设置圆形的边框颜色borderWidth: 5,},tooltip: {valueFormatter: function (value: string) {return value;},},data: lineColumnarData[2],},{name: "谷",type: "bar",itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{//代表渐变色从正上方开始offset: 0, //offset范围是0~1,用于表示位置,0是指0%处的颜色color: "#042231",}, //柱图渐变色{offset: 1, //指100%处的颜色color: "#3ACA73",},]),barBorderRadius: [2, 2, 0, 0],},},tooltip: {valueFormatter: function (value: any) {return value;},},data: lineColumnarData[3],},],};myLineColumnarChart.setOption(lineColumnarOption);
});
</script>

Challenges are what make life interesting and overcoming them is what makes life meaningful.‌

http://www.xdnf.cn/news/616465.html

相关文章:

  • 【ISP算法精粹】ISP算法管线的预处理算法有哪些?
  • Linux之 SPI 驱动框架- spi-mem 框架
  • 虚拟化工具libvirt日志文件的结构化使用指南
  • Python 脚本执行命令的深度探索:方法、示例与最佳实践
  • 蓝桥杯2025.5.23每日一题-儿童数
  • 中科驭数携DPU全栈产品亮相福州数博会,赋能智算时代算力基建
  • Trae 的核心功能介绍
  • OS面试篇
  • BU9792驱动段式LCD
  • C++:无序容器
  • 第十四届蓝桥杯国赛PythonA题解
  • Ubuntu系统下,使用system函数运行终端指令,如何避免输入密码的方法
  • 大数据任务调度实战:DolphinScheduler 与 Airflow 深度解析与最佳实践
  • DAX权威指南4:时间智能计算
  • C++ 结构体封装模式与 Promise 链式调用:设计思想的异曲同工
  • 广东省省考备考(第十八天5.23)—言语:语句填空题(听课后强化训练)
  • Calculix,基于有限元法 (fem) 的免费工具
  • AdGuard解锁高级版(Nightly)_v4.10.36 安卓去除手机APP广告
  • 双均线量化交易策略指南
  • Redis-基础-总结
  • day27- 系统编程之 进程
  • springboot配置redis lettuce连接池,以及连接池参数解释
  • 多语种多场景的的分页详解
  • 哪家的电能质量分析仪最好?
  • 解锁C++递归算法:从原理到实战
  • RAG 和 Fine-Tuning
  • 保持元素的宽高比
  • 【复杂网络分析】社区发现(Community Detection)算法简介
  • Spring Bean的作用域
  • SpringBoot3引入knife4j和knife4j文档请求异常