ECharts仪表盘样式设置

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>ECharts仪表盘样式设置</title>
		<!-- 引入 ECharts 文件 -->
		<script src="echarts.min.js"></script>
	</head>
	<body>
		<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
		<div id="main" style="width: 250px;height: 250px;"></div>
		
		<script>
			// 基于准备好的dom,初始化echarts实例
			var myChart = echarts.init(document.getElementById('main'));
			
			// 指定图表的配置项和数据
			option = {
				title : {  //标题组件
					text: '920',
			        textStyle:{
				        color: '#000',  //文字颜色
				        fontStyle: 'normal',  //字体风格:'normal','italic','oblique'
				        fontWeight: 'normal', //字体粗细 :'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
				        fontFamily: 'sans-serif',//字体系列: 'serif' , 'monospace', 'Arial', 'Courier New', 'Microsoft YaHei', ...
				     	fontSize: 24, //字体大小
				    },
			        x:'center',
			        bottom:0,
			   	},
		        tooltip: {
		            formatter: "{a} <br/>{b} : {c}%",
		        },
		        series: [
		            {
		            	type: 'gauge',
		            	name: '数据指标',
		                radius: '100%',  //仪表盘半径,可以是相对于容器高宽中较小的一项的一半的百分比,也可以是绝对的数值
		                axisLine: {      //仪表盘轴线相关配置
		                	show:true,
		                    lineStyle: {
		                        color: [  //仪表盘背景颜色渐变
				                    [1,new echarts.graphic.LinearGradient(0, 0, 1, 0, [
				                      	{
				                        	offset: 0.1,
				                        	color: "#fd2100"
				                      	},
				                      	{
				                        	offset: 0.6,
				                        	color: "#d09f00"
				                      	},
				                      	{
				                        	offset: 1,
				                        	color: "#26fd00"
				                      	}
				                    ])
				                  ]
				                ],
		                        width:20,  //轴线宽度
		                    },
		                },
		                splitLine: {  //分隔线样式。
			                show: false,
			                interval:0,   //默认会采用标签不重叠的策略间隔显示标签。可以设置成 0 强制显示所有标签。
			                lineStyle:{   //分割线样式
			            		
			            	}
			            },
		                axisLabel: {  // 刻度标签
		                	show:true,
	                    	color: '#000',
	                    	fontSize:10,   //改变仪表盘内刻度数字的大小
	                    	shadowColor : '#000', //默认透明
		                },
		                title: {	//仪表盘标题。
			            	show: true,				//是否显示标题,默认 true。
			            	offsetCenter: [0,"60%"],//相对于仪表盘中心的偏移位置,数组第一项是水平方向的偏移,第二项是垂直方向的偏移。可以是绝对的数值,也可以是相对于仪表盘半径的百分比。
	                        color: '#000',
	                        fontWeight: '100',
	                        fontSize: '18',
			            },
			            
			            detail: {				// 仪表盘详情,用于显示数据。
			            	show: true,				// 是否显示详情,默认 true。
			            	offsetCenter: [0,"35%"],// 相对于仪表盘中心的偏移位置,数组第一项是水平方向的偏移,第二项是垂直方向的偏移。可以是绝对的数值,也可以是相对于仪表盘半径的百分比。
	                        color: '#000',
	                        fontWeight: '700',
	                        fontSize: '20',
			            	formatter: "{value}%",	// 格式化函数或者字符串
			            },
		                data: [{ value: 92, name: '指标' }],
		                markPoint:{  //图表标注
                            symbol:'circle', //'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow', 'none'
                            symbolSize:5,
                            data:[
                                //跟你的仪表盘的中心位置对应上,颜色可以和画板底色一样
                                {x:'center',y:'center',itemStyle:{color:'#FFF'}}
                            ]
                        },
		            }
		        ]
		    };
		    
		    // 使用刚指定的配置项和数据显示图表。
			myChart.setOption(option, true);
		</script>
	</body>
</html>

 

### ECharts 仪表盘样式配置示例 在 ECharts 中,可以通过多种方式来定制仪表盘的外观和行为。下面是一个详细的例子,展示了如何设置指针样式、刻度线以及背景颜色等属性。 #### 基本配置项说明 - `series.type`: 设置为 `'gauge'` 来表示这是一个仪表盘类型的图表[^1]。 - `title`: 可以为整个图表添加标题文字[^2]。 - `detail`: 控制数据显示细节,比如字体大小、偏移量等参数[^3]。 #### 完整代码实例 ```javascript option = { title: { text: 'ECharts Gauge Chart', subtext: '', top: 'bottom' }, series: [{ name: "单仪表盘示例", type: 'gauge', // 使用 gauge 类型创建仪表盘 detail: {formatter:'{value}%'}, // 显示百分比形式的数据详情 pointer: { length : '80%', // 指针长度比例 width : 8 // 指针宽度 }, axisLine: { // 刻度线条样式 lineStyle: { color: [[0.2, '#ff4500'],[0.8, '#ffee77'],[1, '#ffffff']],// 不同区间的颜色渐变 width: 30, shadowBlur: 10, shadowColor: '#fff' // 圆环阴影 } }, splitLine: { // 主分隔线样式(大刻度) show: true, length: 30, lineStyle: { width: 2, color: '#999' } }, axisTick: { // 细分隔线样式(小刻度) show: true, length: 8, lineStyle: { color: 'auto' } }, axisLabel: { // 文字标签样式 distance: 15, color: '#999', fontSize: 12 }, data:[ // 数据源 {value: 50} ] }] }; ``` 此段 JavaScript 代码片段定义了一个具有特定样式ECharts 仪表盘,并设置了不同部分的颜色、尺寸和其他视觉特性。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值