echarts柱状图怎么设置上下滚动
时间: 2023-11-11 09:00:37 浏览: 115
要设置 echarts 柱状图的上下滚动,可以使用 echarts 的 dataZoom 组件。具体步骤如下:
1. 在 option 中添加 dataZoom 组件:
```
option = {
...
dataZoom: [{
type: 'slider',
yAxisIndex: 0,
start: 0,
end: 50
}]
...
}
```
2. 在 xAxis 中设置 axisLabel 的 interval 属性,控制 x 轴标签的显示间隔:
```
option = {
...
xAxis: {
type: 'category',
data: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'],
axisLabel: {
interval: 0, // 显示所有标签
rotate: 45, // 标签旋转角度
margin: 10, // 标签与轴线的距离
textStyle: {
color: '#333',
fontSize: 12
}
}
},
...
}
```
3. 在 yAxis 中设置 min 和 max 属性,控制 y 轴的显示范围:
```
option = {
...
yAxis: {
type: 'value',
min: 0,
max: 100,
axisLabel: {
textStyle: {
color: '#333',
fontSize: 12
}
}
},
...
}
```
4. 在 series 中设置 markLine 组件,用于标记当前显示的数据范围:
```
option = {
...
series: [{
name: '数据',
type: 'bar',
data: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130],
markLine: {
symbol: 'none',
label: {
show: false
},
lineStyle: {
color: '#999'
},
data: [{
yAxis: 50 // 标记当前显示的数据范围
}]
}
}]
...
}
```
阅读全文
相关推荐













