Echarts 模拟汽车速度和油量的仪表显示,两个仪表盘同图-灵析社区

JACKY

本示例的目标是模拟汽车速度和油量的仪表显示,这里两个仪表盘同图,并倾斜一定的角度。

示例效果

示例源代码(共115行)


/*
* @Author: 还是大剑师兰特(CSDN)
* @下面源代码版权归还是大剑师兰特所有,可供学习或商业项目中借鉴,未经授权,不得重复地发表到博客、论坛,问答,git等公共空间或网站中。
* @Email: 2909222303@qq.com
* @First published in CSDN
* @First published time: 2023-02-27
*/
<template>
	<div class="container">
		<h3>vue+echarts:两个仪表盘同图,模拟汽车速度和油量的仪表显示</h3>
		<p>大剑师兰特,还是大剑师兰特</p>
		<div id="vue-echarts" ref="refEcharts"> </div>
		<div class="car"><img src="../assets/car.png" ></div>
	</div>
</template>

<script>
	import * as echarts from 'echarts'; //局部引用,如果采用全局模式,这里不写
	export default {
		name: 'cuclife',
		data() {
			return {}
		},
		methods: {
			initCharts() {
				let myChart = echarts.init(this.$refs.refEcharts);
                let mycolor = [[0.35, "rgba(0,0,255,1)"], [0.6, "rgba(0,255,0,1)"], [1, "rgba(255,0,0,1)"]];
				let mycolor2 = [[0.15, "red"], [0.3, "orange"], [1, "green"]];
				myChart.setOption({
					title: {
						text: '还是大剑师兰特的ECharts仪表盘示例'
					},
					series: [{
						name: "Indicator1",
						type: "gauge",
						center: ['30%', '50%'],
						detail: {
							formatter: "{value}"
						},
						max:200, //最高速度200
						startAngle: 240, //核心代码
						endAngle: 30,  //核心代码
						axisLine: { 
							show: true, 
							lineStyle: {
								color: mycolor, 
							}
						},

						data: [{
							value: 120,
							name: "公里/小时",
							itemStyle: {
								color: 'blue'
							}
						}]
					},
					{
						name: "Indicator2",
						type: "gauge",
						center: ['70%', '50%'],
						detail: {
							formatter: "{value}%"
						},
						// clockwise:false,
						startAngle: 150, 
						endAngle: -60,  
						axisLine: { 
							show: true, 
							lineStyle: {
								color: mycolor2, 
							}
						},
					
						data: [{
							value: 50,
							name: "剩余油量",
							itemStyle: {
								color: 'red'
							}
						}]
					}
					]
				});
			}
		},
		mounted() {
			this.initCharts();
		}
	}
</script>
<style scoped>
	.container {
		width: 840px;
		height: 580px;
		margin: 50px auto 0;
		border: 1px solid rgb(228, 57, 97);
		position: relative;
	}
	.car{ 
		position: absolute;
		z-index: 10;
		width: 174px;
		height: 115px;
		left: calc( 50% - 87px );
		bottom:70px
	}

	#vue-echarts {
		width: 800px;
		height: 460px;
		border: 1px solid #d8d;
		margin: 0 auto;
	}
</style>


阅读量:526

点赞量:0

收藏量:0