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

Echarts自定义横向柱状图中单条bar的样式

需要解决的样式难点,柱条渐变色,末端白色矩形,以及每条柱的百分比。

<template><div class="panel-wrapper"><header>各网格完成率</header><Echart :options="options" width="100%" height="344px" /></div>
</template><script>
import Echart from "@/common/echart";
export default {components: {Echart,},data() {return {options: {grid: {left: 80,top: 30,bottom: 0,right: 100,},xAxis: {show: false,type: "value",},yAxis: {type: "category",data: ["第一网格","第二网格","第三网格","第四网格","第五网格","第六网格","第七网格","第八网格",],axisLine: {show: false, // 去掉 y 轴的线},axisLabel: {color: "#C3E7FF", // 文字颜色fontSize: 14, // 文字大小},},series: [{type: "bar",barWidth: 11,itemStyle: {color: {type: "linear",x: 0,y: 0,x2: 1,y2: 0,colorStops: [{offset: 1,color: "#78B6F3",},{offset: 0,color: "rgba(17, 70, 124, 0)",},],},},// label: {//   show: true,//   position: "right", // 在柱条右端显示//   formatter: "{c}%", // {c} 代表数值,拼接百分号//   color: "#C3E7FF",//   fontSize: 14,// },data: [11, 12, 3, 4, 5, 6, 7, 10],},{name: "右端矩形",type: "custom",renderItem: function (params, api) {// 横向:value 在 x 轴,category 在 y 轴const categoryIndex = api.value(0); // 类目索引const barValue = api.value(1); // 数值// 转成像素坐标const endCoord = api.coord([barValue, categoryIndex]);const x = endCoord[0];const y = endCoord[1];const rectWidth = 5; // 矩形宽度const rectHeight = 15; // 与柱条一样高(或者小点)return {type: "rect",shape: {x: x,y: y - rectHeight / 2,width: rectWidth,height: rectHeight,},style: {fill: "#FFF", // 矩形颜色},};},encode: {x: 1, // 第1个维度 = 数值 → x轴y: 0, // 第0个维度 = 类目 → y轴},data: [["第一网格", 11],["第二网格", 12],["第三网格", 3],["第四网格", 4],["第五网格", 5],["第六网格", 6],["第七网格", 7],["第八网格", 10],],},{// 自定义右侧标签type: "custom",renderItem: function (params, api) {const categoryIndex = params.dataIndex;const value = api.value(1);// 计算标签位置(图表最右侧)const point = api.coord([100, categoryIndex]);return {type: "text",position: [params.coordSys.width + 150, point[1] - 7],style: {text: value + "%",fill: "#fff",fontSize: 18,textAlign: "right",fontWeight: "bold",},z2: 100,};},data: [["第一网格", 11],["第二网格", 12],["第三网格", 3],["第四网格", 4],["第五网格", 5],["第六网格", 6],["第七网格", 7],["第八网格", 10],],z: 3,},],},};},
};
</script><style lang="scss" scoped>
.panel-wrapper {header {background-image: url("./images/i17.png");height: 50px;background-position: center;background-size: 100% auto;background-repeat: no-repeat;color: #fff;// font-family: YouSheBiaoTiHei;font-size: 18px;line-height: 50px;box-sizing: border-box;padding-left: 36px;text-shadow: 0px 1.82px 4.54px rgba(0, 0, 0, 0.3);}
}
</style>

options是图例的配置项。

http://www.dtcms.com/a/363064.html

相关文章:

  • 从模态融合到高效检索:微算法科技 (NASDAQ:MLGO)CSS场景下的图卷积哈希方法全解析
  • 九月科技瞭望:中国科技发展规划动态洞察
  • DevExpress WPF中文教程:如何将WPF数据网格绑定到本地数据库?
  • Python 2025:量子计算、区块链与边缘计算的新前沿
  • [Linux]学习笔记系列 -- mm/swap.c 交换机制(Swap Mechanism) 物理内存的虚拟扩展
  • Linux92 shell:倒计时,用户分类
  • 【JavaEE】多线程案例
  • 删除⽂件之git
  • 前端20个高效开发的JS工具函数
  • 《水浒智慧》第二部“英雄是怎么炼成的”(下篇)读书笔记
  • 宋红康 JVM 笔记 Day11|直接内存
  • 怎么用redis lua脚本实现各分布式锁?Redisson各分布式锁怎么实现的?
  • Higress云原生API网关详解 与 Linux版本安装指南
  • lua脚本在redis中如何单步调试?
  • docker 安装 redis 并设置 volumes 并修改 修改密码(二)
  • MATLAB矩阵及其运算(四)矩阵的运算及操作
  • 互联网大厂求职面试记:谢飞机的搞笑答辩
  • Linux为什么不是RTOS
  • 对矩阵行化简操作几何含义的理解
  • 集群无法启动CRS-4124: Oracle High Availability Services startup failed
  • TSMC-1987《Convergence Theory for Fuzzy c-Means: Counterexamples and Repairs》
  • uni-app 实现做练习题(每一题从后端接口请求切换动画记录错题)
  • Nginx的反向代理与正向代理及其location的配置说明
  • 久等啦!Tigshop O2O多门店JAVA/PHP版本即将上线!
  • SpringBoot3 + Netty + Vue3 实现消息推送(最新)
  • B树和B+树,聚簇索引和非聚簇索引
  • 云计算学习100天-第44天-部署邮件服务器
  • vscode炒股插件-韭菜盒子AI版
  • 小白H5制作教程!一分钟学会制作企业招聘H5页面
  • Linux 环境配置 muduo 网络库详细步骤