项目中使用简单的立体3D柱状图,不用引入外部组件纯css也能实现

在一些项目需求中,可能会遇到下面这种场景,3d柱状图来展示百分比,但是又不想引入外部组件,下面就用纯css给大家封装了一个组件

先赞后看,养成习惯   

<template>
	<view class="lui-column-bg" :style="{width:width+'rpx',height:height+'rpx'}" :class="color">
		<view class="lui-inner" :class="colorCLass" :style="{ height: num + '%' }"></view>
		<view class="text-box">
			<view class="label">{{ label }}</view>
			<view class="value">{{ num ? num + "%" : "暂无" }}</view>
		</view>
	</view>
</template>
<script>
	export default {
		name: "Cylinder",
		props: {
			label: {
				type: String,
				default: ""
			},
			num: {
				type: Number,
				default: 50
			}, // 这个就是圆柱中的数据占比 +
			width: {
				type: Number,
				default: 110
			},
			height: {
				type: Number,
				default: 60
			}
		},
		data() {
			return {};
		},
		computed: {
			colorCLass() {
				if (this.num >= 51) {
					return "success-class";
				}
				if (this.num > 30 && this.num <= 50) {
					return "warning-class";
				}
				if (this.num > 0 && this.num <= 30) {
					return "danger-class";
				}
				if (this.num == 0) {
					return "null-class"
				}
			},
			color() {
				if (this.num >= 51) {
					return "success";
				}
				if (this.num > 30 && this.num <= 50) {
					return "warning";
				}
				if (this.num > 0 && this.num <= 30) {
					return "danger";
				}
				if (this.num == 0) {
					return "null"
				}

			},
		},
		mounted() {},
		methods: {}
	};
</script>
<style lang="less" scoped>
	.lui-column-bg {
		position: relative;
		width: 120rpx;
		height: 60rpx;
		margin: 0 10rpx;
		border-left: 2rpx solid red;
		border-right: 2rpx solid red;
		// margin: 100px;
	}

	.lui-column-bg:before {
		position: absolute;
		content: "";
		display: block;
		height: 40rpx;
		width: 100%;
		border-radius: 50%;
		top: -21rpx;
		z-index: 63;
		border: 2rpx solid red;
	}

	.lui-column-bg:after {
		position: absolute;
		content: "";
		display: block;
		height: 60rpx;
		width: 100%;
		border-radius: 50%;
		bottom: -30rpx;
		background-color: #e8e8e8;
	}

	.lui-inner {
		position: absolute;
		bottom: 0;
		width: 100%;
		height: 50%;
		text-align: center;
	}

	.lui-inner::before {
		position: absolute;
		content: "";
		display: block;
		height: 40rpx;
		width: 100%;
		// background-color: #eec967;
		border-radius: 50%;
		top: -21rpx;
		z-index: 11;
	}

	.lui-inner:after {
		position: absolute;
		z-index: 10;
		content: "";
		display: block;
		height: 60rpx;
		width: 100%;
		border-radius: 50%;
		background-color: #ff6868;
		bottom: -28rpx;
	}

	.text-box {
		position: absolute;
		z-index: 20;
		font-size: 14px;
		top: 50%;
		text-align: center;
		width: 100%;

		.label {
			margin-bottom: 10px;
		}

		.value {
			color: #fff;
		}
	}

	.danger-class {
		background-color: #f294a0;

		&::before {
			background-color: #e1677a;
		}

		&::after {
			background-color: #f294a0;
		}
	}

	.success-class {


		background-color: rgb(0, 156, 222);

		&::before {
			background-color: rgb(1, 111, 160, 1);
		}

		&::after {
			background-color: rgb(0, 156, 222);
		}
	}

	.warning-class {
		background-color: rgb(255, 165, 0, 1);

		&::before {
			background-color: rgb(177, 112, 0);
		}

		&::after {
			background-color: rgb(255, 165, 0, 1);
		}
	}

	.danger {
		color: #e1677a !important;
		border-color: #e1677a !important;

		&::before {
			border-color: #e1677a !important;
		}
	}

	.success {

		color: rgb(0, 156, 222) !important;
		border-color: rgb(0, 156, 222) !important;

		&::before {
			border-color: rgb(0, 156, 222) !important;
		}
	}

	.warning {
		.value {
			color: #fff;
		}

		color: rgb(255, 165, 0, 1);
		border-color: rgb(255, 165, 0, 1) !important;

		&::before {
			border-color: rgb(255, 165, 0, 1) !important;
		}
	}

	.null {
		.value {
			color: #000;
		}

	}
</style>

 在需要使用的地方直接引入使用就好了,只传百分比,宽高有需要再传

要在Echarts实现立体柱状图,可以使用Echarts的3D效果。以下是使用Vue框架和Echarts库实现立体柱状图的步骤: 1. 安装Echarts库:在Vue项目使用npm或yarn安装Echarts库。 ``` npm install echarts --save ``` 2. 在Vue组件引入Echarts库: ``` import echarts from 'echarts' ``` 3. 创建一个Echarts图表容器,例如: ``` <div ref="chart" style="width:600px;height:400px;"></div> ``` 4. 在Vue组件使用Echarts库的API创建一个立体柱状图: ``` mounted() { // 基于准备好的dom,初始化echarts实例 let myChart = echarts.init(this.$refs.chart); // 指定图表的配置项和数据 let option = { tooltip: {}, visualMap: { max: 20, inRange: { color: ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026'] } }, xAxis3D: { type: 'category', data: ['A', 'B', 'C', 'D', 'E'] }, yAxis3D: { type: 'category', data: ['2012', '2013', '2014', '2015', '2016'] }, zAxis3D: { type: 'value' }, grid3D: { boxWidth: 200, boxDepth: 80, viewControl: { // projection: 'orthographic' }, light: { main: { intensity: 1.2, shadow: true }, ambient: { intensity: 0.3 } } }, series: [{ type: 'bar3D', data: [ [0, 0, 5], [0, 1, 1], [0, 2, 0], [0, 3, 2], [0, 4, 1], [1, 0, 1], [1, 1, 5], [1, 2, 3], [1, 3, 0], [1, 4, 2], [2, 0, 0], [2, 1, 3], [2, 2, 5], [2, 3, 1], [2, 4, 1], [3, 0, 2], [3, 1, 0], [3, 2, 3], [3, 3, 5], [3, 4, 2], [4, 0, 1], [4, 1, 2], [4, 2, 1], [4, 3, 2], [4, 4, 5] ], shading: 'lambert', label: { textStyle: { fontSize: 16, borderWidth: 1 } }, emphasis: { label: { textStyle: { fontSize: 20, color: '#900' } }, itemStyle: { color: '#900' } } }] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); } ``` 这是一个简单立体柱状图示例,你可以根据自己的需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端_彭于晏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值