echarts 柱状图隐藏x、y轴坐标轴、刻度线、隐藏x、y轴坐标轴的数值

本文介绍如何使用ECharts隐藏柱状图的X、Y轴坐标轴、刻度线及数值等元素,通过调整配置项实现图表的定制化需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

echarts 柱状图隐藏x、y轴的内容,隐藏x,y轴坐标轴、刻度线、隐藏x、y轴坐标轴的数值

1.隐藏x轴坐标轴,在xAxis下使用axisLine属性为false,相反显示则是true
axisLine:{     //x轴坐标轴,false为隐藏,true为显示
	"show":false
},

eachsrts002

2.隐藏x轴坐标轴的数值,在xAxis下使用axisLabel属性为false,相反显示则是true
axisLabel:{ show: true }, //显示x轴的数值

eachrst002

3.隐藏x轴坐标轴刻度线,在xAxis下使用axisTick属性为false,相反显示则是true
axisTick: {		//x轴刻度线
	show:true
},

eachrts003

4.X轴整体代码
xAxis: {
	show:true,
	type: 'value',
	splitLine:{
    show:true
  },
	"axisLine":{     //x轴坐标轴
		"show":true
	},
	axisLabel:{ show: true },
	axisTick: {		//x轴刻度线
		show:true,
		alignWithLabel: true,
	},
},

eacharts004

5.如图是不想显示的x轴代码

eachrts001

全部代码如下
<div id="main5" style="width: 100%;height: 434px;"></div>
var chartFnc = {
	init: function() {;
		this.chartGraphFnc();
	},
	chartGraphFnc: function () {	// 柱状图 查看次数
		var myChart = echarts.init(document.getElementById('main5'));
		var option = {
			grid: {
				left: '3%',
				right: '4%',
				bottom: '6%',
				width:"auto",
				containLabel: true
			},
			xAxis: {
				show:true,
				type: 'value',
				splitLine:{
			    show:true
			  },
				"axisLine":{     //x轴坐标轴
					"show":false
				},
				axisLabel:{
					show: false
				},
				axisTick: {		//x轴刻度线
					show:false
				},
			},
			yAxis: {
				type: 'category',
				data: ['1-10次', '11-20次', '21-40次', '41-60次', '61-80次', '91-100次', '101-150次', '151-200次', '201-300次', '301次以上'],
				// show:false,
				axisLine:{
					show:false
				},
				axisTick: {
					show:false,
					alignWithLabel: true,
				},
				splitArea : {show : false},
			},
			series: [{
				data: [160, 29, 150, 80, 70, 130,12,20,40,80],//假数据
				type: 'bar',
				showBackground: true,
				backgroundStyle: {
					color: 'rgba(180, 180, 180, 0.2)'
				},
				barWidth : 22,//柱图宽度
				itemStyle:{
					normal: {
						label: {
							show: true,	//是否展示
							position: 'right', //在上方显示
							textStyle: {	//数值样式,显示的文字大小和颜色
								fontSize : '12',
								color: '#0A1F44'
							}
						},
						color: '#6f96fe' //蓝色
					}
				},
			}]
		};

		// 为echarts对象加载数据
		myChart.setOption(option);
		},
	}
	// 初始化图表组件
	chartFnc.init();
});

注:如果想改变y轴内容,则跟x轴相反,放到yAxis里即可!!!

### ECharts线图 X 和 Y 坐标的不同配置方法 在 ECharts 中,可以通过 `option` 对象中的 `xAxis` 和 `yAxis` 参数来分别配置 X 和 Y 的样式、显示方式以及其他属性。以下是详细的说明和示例代码。 #### 1. **X 配置** X 通常作为分类使用,在折线图中表示时间或其他类别数据。通过以下参数可以自定义 X : - `type`: 类型,常见的是 `'category'` 表示离散类目。 - `boundaryGap`: 如果为 `false`,则柱状图会紧贴着坐标轴两端[^3]。 - `data`: 数据数组,指定 X 上的具体值。 - `axisLabel`: 控制刻度标签的显示方式,比如旋转角度 (`rotate`) 或间隔 (`interval`) 显示[^3]。 ```javascript xAxis: [{ type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], axisLabel: { interval: 0, // 所有标签都显示 rotate: -45 // 刻度标签倾斜一定角度 } }] ``` --- #### 2. **Y 配置** Y 通常是数值,用来展示具体的数值范围。主要参数如下: - `type`: 常见类型为 `'value'`,表示连续数值。 - `min`, `max`: 自定义 Y 的最小值和最大值。 - `splitLine`: 控制网格分割线的显示与否。 - `formatter`: 可以格式化 Y 刻度标签的内容[^1]。 ```javascript yAxis: [{ type: 'value', min: 0, max: 100, splitLine: { show: true }, axisLabel: { formatter: '{value} °C' } }] ``` --- #### 3. **完整的折线图配置示例** 下面是一个综合的例子,展示了如何配置 X 和 Y 并绘制一条简单的折线图。 ```javascript var chartDom = document.getElementById('main'); var myChart = echarts.init(chartDom); var option; option = { title: { text: '简单折线图示例' }, tooltip: { trigger: 'axis' }, legend: { data: ['温度'] }, xAxis: { type: 'category', boundaryGap: false, data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], axisLabel: { interval: 0, rotate: -45 } }, yAxis: { type: 'value', min: 0, max: 100, splitLine: { show: true }, axisLabel: { formatter: '{value} °C' } }, series: [ { name: '温度', type: 'line', data: [12, 13, 10, 15, 18, 20, 16], markPoint: { data: [{ type: 'max', name: '最高点' }] } } ] }; myChart.setOption(option); ``` --- #### 4. **动态加载数据** 如果需要动态更新图表的数据,可以在初始化之后调用 `setOption` 方法重新渲染图表。 ```javascript function updateData(newXData, newYData) { var updatedOption = { xAxis: { data: newXData }, series: [{ data: newYData }] }; myChart.setOption(updatedOption); } updateData(['A', 'B', 'C'], [20, 30, 40]); ``` --- ### 问题
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值