开发者社区> 问答> 正文

echarts,xAxis类型为time时,boundaryGap坐标轴两边留白策略设置无效。

echarts官网的api中有这么一段:
xAxis.boundaryGap
坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样。
类目轴中 boundaryGap 可以配置为 true 和 false。默认为 true,这时候刻度只是作为分隔线,标签和数据点都会在两个刻度之间的带(band)中间。
非类目轴,包括时间,数值,对数轴,boundaryGap是一个两个值的数组,分别表示数据最小值和最大值的延伸范围,可以直接设置数值或者相对的百分比,在设置 min 和 max 后无效。 示例:
boundaryGap: ['20%', '20%']

可是为什么x轴的type:time类型时候就无效呢???

源码如下:

option = {
  	"title":{"text":"玩家充值","link":"javascript: void(0)","target":"self","subtext":"单位:元","x":"left"},
			 toolbox: {
				show: true,
				orient:'vertical',
				right:'25',
				feature: {
					magicType: {
						 type: ['line', 'bar', 'stack', 'tiled']	//折线与柱形转化
						
					},
					//dataView: {},				//数据视图
					restore: {},				//还原
					saveAsImage: {}				//保存为图片
				}
			},
			"tooltip":{"trigger":"axis","axisPointer":{"type":"line"},formatter:''},
			"legend":{
				"left":"center",
				"data":["捕鱼","斗地主","牛牛"] 
				},
			"grid":{"left":"3%","right":"4%","bottom":"3%","containLabel":true},
			"xAxis":{"type":"time",
					 "boundaryGap":['20%', '20%']
					},
			"yAxis":{"type":"value"},
			"series":[
				{"name":"斗地主","type":"bar","stack":"总量","data":[["2017-12-04 00:00:00",130.888],["2017-12-05 00:00:00",380.3698],["2017-12-06 00:00:00",320],["2017-12-07 00:00:00",320]]},
				{"name":"捕鱼","type":"bar","stack":"总量","data":[["2017-12-04 00:00:00",125],["2017-12-05 00:00:00",410],["2017-12-06 00:00:00",520],["2017-12-07 00:00:00",320]]},
				{"name":"牛牛","type":"bar","stack":"总量","data":[["2017-12-04 00:00:00",275],["2017-12-05 00:00:00",220],["2017-12-06 00:00:00",498],["2017-12-07 00:00:00",320]]}]
};

显示结果如下:

![image.png](https://ucc.alicdn.com/pic/developer-ecology/b4ac041fbd4e46f482f15bfe9099d3ca.png)

两边并没有留白?
求大佬赐教,跪谢。

展开
收起
huc_逆天 2020-05-28 09:18:15 1387 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载