echarts 实现3D立体柱状图示例

该示例有如下几个特点:

        ①实现tooltip自定义样式(echarts 实现tooltip提示框样式自定义-CSDN博客)

        ②数据为0时,顶部四边形不展示

        ③legend图标设置为自定义图片

【第②也是一个难点,我没有找到其他解决办法,暂时就把color写成函数进行判断,数据为0时设置颜色透明,若有其他更好的解决办法,相互交流呀~】

代码如下:

<template><div class="content"><Echartid="aircraftDistributionChart":options="options":height="height":width="width":clickFn="getDetailInfo"/></div>
</template><script>
import Echart from "@/components/Echart/index.vue";
import * as echarts from "echarts";
export default {name: "aircraftDistributionChart",props: ["width", "height"],components: {Echart},data() {return {type: 0,options: {},xAxisData: ["机场1", "机场2"],legendData: [],seriesData: {"飞机1": [3,5],"飞机2": [4,2],"飞机3": [0,4]},title: "飞机分布",loadingStyle: null,data: [],clientWidth: document.body.clientWidth,colorList: [{offset0: "#00FCFF",offset1: "#00A8FF",},{offset0: "#FFE8D6",offset1: "#FFA800",},{offset0: "#A1C1FF",offset1: "#654BFF",},{offset0: "#05FF00",offset1: "#EAFFD6",},{offset0: "#FFC7DB",offset1: "#FF1485",},{offset0: "#FFB8B2",offset1: "#FF7165",},{offset0: "#E8CCFF",offset1: "#AF82FB",},{offset0: "#CAF6FB",offset1: "#2DDBF0",},{offset0: "#FFF8CB",offset1: "#FFEA53",},{offset0: "#FCC2EE",offset1: "#F970D7",},],};},mounted() {this.getData();},methods: {async getDetailInfo(e) {},async getData() {let that = this;let data = JSON.parse(JSON.stringify(this.seriesData));let tempData = Object.keys(data);this.legendData = [];this.seriesData = [];for (let i = 0; i < tempData.length; i++) {let temKey = tempData[i];let leg = {name: tempData[i],icon: "path://M 869.188 431.844 H 726.763 L 471.95 118.25 h -117.563 l 117.563 313.594 H 231.875 L 131.469 352.25 H 62 l 59.175 236.419 h 350.775 l -117.563 313.594 h 117.563 l 254.813 -313.594 h 196.031 c 16.875 0 39.2062 0 39.2062 -39.2062 c 0 -52.0875 -40.6125 -117.563 -92.8125 -117.563 Z",};let arr = [{name: temKey,type: "bar",barWidth: 16,itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{//只要修改前四个参数就okoffset: 0,color: that.colorList[i].offset0,}, //柱图渐变色{offset: 1,color: that.colorList[i].offset1,},]),barBorderRadius: [0, 0, 0, 0],opacity: "1",},},data: data[temKey],barGap: "20%",},{name: temKey,tooltip: {show: false,},type: "pictorialBar",itemStyle: {normal: {color: function (params) {if (params.value == 0) {return "rgba(255,255,255,0)";} else {return new echarts.graphic.LinearGradient(0,1,0,0,[{//只要修改前四个参数就okoffset: 0,color: that.colorList[i].offset0,}, //柱图渐变色{offset: 1,color: that.colorList[i].offset1,},]);}},borderWidth: 1,borderColor: "rgba(0,252,255,0.6)",opacity: "1",shadowColor: "rgb(0,0,0,0.1)",shadowOffsetX: "0.5",shadowOffsetY: "0.5",},},symbol: "rect",symbolRotate: 45,symbolSize: ["12", "12"],symbolOffset: [(tempData.length - 1) * -9.5 + i * 19, "-8"],symbolPosition: "end",data: data[temKey],z: 3,},];this.legendData.push(leg);this.seriesData = this.seriesData.concat(arr);}this.creatChart();},// 根据屏幕宽度处理数据handleWidth(data) {return ((this.clientWidth / 1920) * data).toFixed(0);},creatChart() {this.options = {tooltip: {trigger: "axis",axisPointer: {type: "shadow"},textStyle: {align: "left"},className: "custom-tooltip-box",formatter: function (params) {let tip = "";for (let i = 0; i < params.length; i++) {let a = "";a = `<div class="span"><span>${params[i].seriesName}:</span><span>${params[i].value} 架</span></div>`;tip = tip + a;}let height = params.length * 3.3 + 5;return `<div class='custom-tooltip-style' style="height: ${height}rem"><span>${params[0].name}</span></br>${tip}`;}},legend: {type: "scroll",data: this.legendData,align: "left",right: 10,textStyle: {color: "#ffffff"},pageTextStyle: {color: "#35ffff",fontSize: this.handleWidth(12)},pageIconColor: "#aaa",pageIconInactiveColor: "#555657",textStyle: {color: "#C7F1FF",fontSize: this.handleWidth(12)},itemWidth: 20,itemHeight: 20,itemGap: 15,// 暂时设置不能点击selectedMode: false},grid: {top: "25%",left: "5%",right: "5%",bottom: "6%",containLabel: true},xAxis: [{type: "category",nameTextStyle: {color: "#5C6C75"},offset: 6,axisLine: {show: true,lineStyle: {color: "#355d8d" // 坐标轴线线的颜色}},splitLine: {show: false},axisTick: {show: false},axisLabel: {show: true,textStyle: {color: "#fff" //X轴文字颜色},fontSize: "12", //x轴字体大小rotate: 15},data: this.xAxisData}],yAxis: [{type: "value",name: "单位:架",nameTextStyle: {fontSize: this.handleWidth(12),color: "#FFFFFF99"},axisLabel: {show: true,margin: 14,fontSize: 12,textStyle: {color: "#FFFFFF99"}},axisTick: {show: false},axisLine: {show: false},splitLine: {show: true,lineStyle: {color: "#87C2FF66",width: 0.7,type: "dashed"}}}],series: this.seriesData}}}
};
</script><style lang="scss" scoped>
.content {width: 100%;height: 100%;margin-top: 1.5rem;
}
::v-deep .custom-tooltip-box {padding: 0 !important;border: none !important;background-color: transparent !important;// 给子盒子自定义样式.custom-tooltip-style {width: 18rem;min-height: 8rem;background: url("../../../../assets/images/tooltip-bg-big1.png") no-repeatcenter center;background-size: 100% 100%;color: #fff;display: flex;flex-direction: column;justify-content: space-around;padding: 1rem 2rem;font-size: 1.4rem;.span {display: flex;justify-content: space-between;margin-top: 0.5rem;:last-child {font-weight: 600;font-size: 1.4rem;}}}
}
</style>

效果图如下:

该示例中的属性可在官网中查阅,若有其他疑问可私信留言互相交流学习~

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

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

相关文章

【性能测试】稳定性测试要点-监控关键指标总结(超细整理)

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 1、稳定性测试的要…

论文阅读:“iOrthoPredictor: Model-guided Deep Prediction of Teeth Alignment“

文章目录 IntroductionMethodologyProblem FormulationConditional Geometry GenerationTSynNetAligned Teeth Silhouette Maps Generation ResultsReferences Github 项目地址&#xff1a;https://github.com/Lingchen-chen/iOrthopredictor Introduction 这篇文章提出了一种…

软件测试面试时问你的项目经验,你知道该怎么说吗?

很简单&#xff0c;我来给你们一个公式 0 自我介绍&#xff0c;名字 学历 荣誉。 1 简述项目背景&#xff0c;你身处这个项目是做什么的。 不要太细&#xff0c;试着引导一下面试官让他提问。这样&#xff0c;请问您对此有什么疑问吗&#xff1f; 2 简述 你在项目中的角色&…

uniapp小程序定位;解决调试可以,发布不行的问题

遇见这个问题&#xff1b;一般情况就两种 1、域名配置问题&#xff1b; 2、隐私协议问题 当然&#xff0c;如果你的微信小程序定位接口没开启&#xff1b;定位也会有问题&#xff1b; 第一种&#xff0c;小程序一般是腾讯地图&#xff1b;所以一般都会用https://apis.map.qq.co…

Django 入门学习总结2 创建一个投票系统

通过学习&#xff0c;我们可以实现一个简单的投票系统。这个投票系统有两部分组成。 公共部分&#xff0c;公众可以查看和进行投票。管理员可以进行增加、删除、修改投票信息。 这里投票系统Python语言版本为3.10.13&#xff0c;Django Web框架版本为4.2.7。 投票系统的实现…

git修改commit历史提交时间、作者

1、修改最近的几条记录&#xff0c;进入提交记录列表&#xff0c;修改提交记录模式 git rebase -i HEAD~3 // 修改最近的三条记录&#xff0c;顺序排列按提交时间升序 指令说明&#xff1a; pick&#xff1a;保留该commit&#xff08;缩写:p&#xff09; reword&#xff1a…

lvm操作和扩容根分区

扩展逻辑卷 [rootlocalhost ~]# pvcreate /dev/sdb1 vgextend vg1 /dev/sdb1&#xff08;表示将/dev/sdb1扩展到centos卷组&#xff0c;扩展卷组就是将其它分好的区加入卷组&#xff09; [rootlocalhost ~]# vgextend centos /dev/sdb1[rootlocalhost ~]# lvextend -L 50G /…

事关Django的静态资源目录设置与静态资源文件引用(Django的setting.py中的三句静态资源(static)目录设置语句分别是什么作用?)

在Django的setting.py中常见的三句静态资源(static)目录设置语句如下&#xff1a; STATICFILES_DIRS [os.path.join(BASE_DIR, static_list)] # 注意这是一个列表,即可以有多个目录的路径 STATIC_ROOT os.path.join(BASE_DIR, static_root) STATIC_URL /static-url/本文介…

CImage通过WinApi的SetWorldTransform来实现图片旋转

SetWorldTransform的功能是旋转画布&#xff0c;这样产生的效果就是图像旋转。因此&#xff0c;在旋转画布之前&#xff0c;要把要旋转的图像的位置和大小准备好&#xff0c;这样旋转之后&#xff0c;才能使图像正好出现在显示区域内。这需要计算两个关键参数&#xff0c;图像的…

Kotlin学习——hello kotlin 函数function 变量 类 + 泛型 + 继承

Kotlin 是一门现代但已成熟的编程语言&#xff0c;旨在让开发人员更幸福快乐。 它简洁、安全、可与 Java 及其他语言互操作&#xff0c;并提供了多种方式在多个平台间复用代码&#xff0c;以实现高效编程。 https://play.kotlinlang.org/byExample/01_introduction/02_Functio…

如何进行手动脱壳

脱壳的目的就是找到被隐藏起来的OEP&#xff08;入口点&#xff09; 这里我一共总结了三种方法&#xff0c;都是些自己的理解希望对你们有用 单步跟踪法 一个程序加了壳后&#xff0c;我们需要找到真正的OEP入口点&#xff0c;先运行&#xff0c;找到假的OEP入口点后&#x…

SpringBoot 整合 JdbcTemplate(配置多数据源)

数据持久化有几个常见的方案&#xff0c;有 Spring 自带的 JdbcTemplate 、有 MyBatis&#xff0c;还有 JPA&#xff0c;在这些方案中&#xff0c;最简单的就是 Spring 自带的 JdbcTemplate 了&#xff0c;这个东西虽然没有 MyBatis 那么方便&#xff0c;但是比起最开始的 Jdbc…