echarts 之 科技感进度条

1.图片展示

在这里插入图片描述

2.代码实现

/* ng qty 进度条 */
<template>
	<div class="ngqty-progress">
		<div class="ngqty-info">
			<span>X4</span>
			<span>50%</span>
		</div>
		<div :id="'barNgQtyProgress' + index" class="chart"></div>
	</div>
</template>
<script>
import echarts from "echarts";

export default {
	name: "bar-ngqty-progress",
	props: {
		index: {
			type: String, // String, Number, Object
			required: false,
			default: "0",
		},
		data: {},
	},
	data() {
		return {
			chart: {},
		};
	},
	methods: {
		initChart() {
			this.chart = echarts.init(document.getElementById("barNgQtyProgress" + this.index));
			let category = [{ name: "省外资金", value: "50" }]; // 类别
			let total = 100; // 数据总数
			var datas = [];
			category.forEach((value) => {
				datas.push(value.value);
			});
			let option = {
				grid: {
					left: "0",
					top: "center", // 设置条形图的边距
					right: "0",
				},
				xAxis: {
					max: total,
					show: false,
				},
				yAxis: [
					{
						type: "category",
						inverse: false,
						data: category,
						show: false,
					},
				],
				series: [
					{
						// 内
						type: "bar",
						stack: "1",
						barWidth: 15,
						legendHoverLink: false,
						silent: true,
						itemStyle: {
							normal: {
								color: function () {
									return {
										type: "linear",
										x: 0,
										y: 0,
										x2: 1,
										y2: 0,
										colorStops: [
											{
												offset: 0,
												color: "#011b26", // 0% 处的颜色
											},
											{
												offset: 1,
												color: "#45f2c8", // 100% 处的颜色
											},
										],
									};
								},
							},
						},
						data: category,
						z: 1,
						animationEasing: "elasticOut",
					},

					{
						// 分隔
						type: "pictorialBar",
						itemStyle: {
							normal: {
								color: "#052132",
							},
						},
						symbolRepeat: "true",
						symbolMargin: "90 !",
						symbol: "rect",
						symbolClip: true,
						symbolSize: [10, 28],
						symbolPosition: "start",
						symbolOffset: [1, -1],
						symbolBoundingData: this.total,
						data: category,
						z: 2,
						animationEasing: "elasticOut",
					},
				],
			};
			// 绘制图表
			this.chart.setOption(option, true);
			window.addEventListener("resize", () => {
				if (this.chart) {
					this.chart.resize(); // 不报错
				}
			});
		},
	},
	mounted() {
		this.initChart();
	},
};
</script>
<style lang="less" scoped>
.ngqty-progress {
	width: 98%;
	height: 100%;
	.ngqty-info {
		height: 30px;
		width: 100%;
		margin-bottom: 10px;
		span {
			color: #4bf9ef;
			font-size: 30px;
			font-weight: bold;
			display: inline-block;
			&:nth-child(2) {
				float: right;
			}
		}
	}
	.chart {
		width: 100% !important;
		height: calc(100% - 45px) !important;
	}
	#barNgQtyProgress0 {
		padding: 5px 10px;
		border: 1px solid #44837d;
		border-right: 4px solid #44837d;
		border-left: 4px solid #44837d;
	}
}
</style>

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Echarts提供了一个3D柱状图(bar3D)的组件,我们可以利用这个组件实现一个3D环形进度条。 具体实现步骤如下: 1. 安装Echarts ```bash npm install echarts --save ``` 2. 引入Echarts库 ```html <script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script> ``` 3. 创建一个容器 ```html <div id="chart-container"></div> ``` 4. 初始化Echarts实例 ```js var chart = echarts.init(document.getElementById('chart-container')); ``` 5. 配置Echarts参数 ```js var option = { xAxis3D: { type: 'category', data: ['进度'], }, yAxis3D: { type: 'category', data: [''], }, zAxis3D: { type: 'value', }, grid3D: { boxWidth: 200, boxDepth: 80, viewControl: { autoRotate: true, }, }, series: [ { type: 'bar3D', data: [[0, 0, 0]], shading: 'color', itemStyle: { opacity: 0.6, }, }, { type: 'bar3D', data: [[0, 0, 1]], shading: 'color', itemStyle: { opacity: 0.6, }, }, { type: 'bar3D', data: [[0, 0, 2]], shading: 'color', itemStyle: { opacity: 0.6, }, }, { type: 'bar3D', data: [[0, 0, 3]], shading: 'color', itemStyle: { opacity: 0.6, }, }, ], }; ``` 6. 渲染Echarts图表 ```js chart.setOption(option); ``` 7. 动态更新进度条 ```js function updateProgress(progress) { chart.setOption({ series: [ { data: [[0, 0, progress]], }, ], }); } ``` 完整的代码示例: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>3D环形进度条</title> <script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script> </head> <body> <div id="chart-container"></div> <script> var chart = echarts.init(document.getElementById('chart-container')); var option = { xAxis3D: { type: 'category', data: ['进度'], }, yAxis3D: { type: 'category', data: [''], }, zAxis3D: { type: 'value', }, grid3D: { boxWidth: 200, boxDepth: 80, viewControl: { autoRotate: true, }, }, series: [ { type: 'bar3D', data: [[0, 0, 0]], shading: 'color', itemStyle: { opacity: 0.6, }, }, { type: 'bar3D', data: [[0, 0, 1]], shading: 'color', itemStyle: { opacity: 0.6, }, }, { type: 'bar3D', data: [[0, 0, 2]], shading: 'color', itemStyle: { opacity: 0.6, }, }, { type: 'bar3D', data: [[0, 0, 3]], shading: 'color', itemStyle: { opacity: 0.6, }, }, ], }; chart.setOption(option); function updateProgress(progress) { chart.setOption({ series: [ { data: [[0, 0, progress]], }, ], }); } // test setTimeout(function () { updateProgress(1); }, 1000); setTimeout(function () { updateProgress(2); }, 2000); setTimeout(function () { updateProgress(3); }, 3000); setTimeout(function () { updateProgress(0); }, 4000); </script> </body> </html> ``` 这样就实现了一个简单的3D环形进度条

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值