echarts 渐变仪表盘


实现echarts 渐变仪表盘

效果预览:

 

 

<body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="width: 600px;height:400px;"></div>
    <script type="text/javascript">
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
		var colors=["#e00005","#e6a900","#00c05a"];
		var fontColor="#0089fa";
		var data=[70,2];
		var fontSize=13;
		var percent=data[0]/(data[0]+data[1])*100;
       	var option = {
			backgroundColor:"#05233b",
			series: [
				{
					type: 'gauge',
					name: '外层辅助',
					radius: '86%',
					pointer: {
						show: false
					},
					detail: {
						show: true,
						offsetCenter: [-30,'90%'],
						fontSize:15,
						color: '#fff'
					},
					data: [{
						value: 70,name:"在线:"
					}],
					title: {
						show: true,
						offsetCenter: [-60, '90%'],
						textStyle: {
							color: fontColor,
						}
					},
					axisLine: {
						show: true,
						lineStyle: {
							color: [
								[1, '#0a80d5'],
							],
							width: 5,
							opacity: 1
						}
					},
					axisTick: {
						show: false
					},
					splitLine: {
						show: true,
						length: 20,
						lineStyle: {
							color: '#051932',
							width: 0,
							type: 'solid',
						},
					},
					axisLabel: {
						show: false
					}
				},
				{
					name: '最内层线',
					type: 'gauge',
					radius: '30%',
					center: ['50%', '50%'],
					startAngle: 0,
					endAngle: 359.999,
					axisLine: {
						show: false,
						lineStyle: {
							opacity: 0,
						}
					},
					splitLine: {
						show: false,
						lineStyle: {
							opacity: 0
						}
					},
					axisLabel: {
						show: false
					},
					axisTick: {
						length: 2,
						lineStyle: {
							color: fontColor,
							width: 2,
							type: 'solid'
						}
					},
					detail: {
						show: true,
						offsetCenter: [80,'258%'],
						fontSize:15,
						color: '#fff'
					},
					data: [{
						value: data[1],name:"离线:"
					}],
					title: {
						show: true,
						offsetCenter: [50, '258%'],
						textStyle: {
							color: fontColor,
						}
					},
					pointer: {
						show: false
					}
				},
				{
					name: '内层数据刻度',
					type: 'gauge', 
					radius: '79%',
					min: 0,
					max: 100,
					center: ['50%', '50%'],
					axisLine: {
						lineStyle: {
							width: 30,
							color: [
								[0.1, colors[0]],
								[0.3, new echarts.graphic.LinearGradient(
									0, 1, 0, 0,
									[{
										offset: 0,
										color: colors[0]
									}, {
										offset: 0.8,
										color: colors[1]
									}]
								)],
								[0.7, colors[1]],
								[0.9, new echarts.graphic.LinearGradient(
									0, 1, 0, 0,
									[{
										offset: 0,
										color: colors[2]
									}, {
										offset: 0.6,
										color: colors[1]
									}]
								)],
								[1, colors[2]]
							],
						}
					},
					splitLine: {
						length: 15,
						lineStyle: {
							width: 2,
							color: '#ffffff'
						}
					},
					axisTick: {
						lineStyle: {
							width: 1,
							color: '#ffffff'
						}
					},
					axisLabel: {
						color: fontColor,
						distance: 20,
						fontSize: fontSize,
					},
					detail: {
						show: true,
						offsetCenter: ['0','60%'],
						color: '#fff',
						formatter: function (value) {
							return value.toFixed(1)+"%";
						},
						fontSize:19
					},
					itemStyle: {
						normal: {
							color: 'rgb(0,191,255)'
						}
					},
					data: [{
						value: percent,name:"在线率"
					}],
					silent: false,
					title:{
						offsetCenter : [0, '75%'],//设置在线率位置
						color:fontColor,
					}
				},
			]
		};
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>
</body>

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM