Echarts具有自适应的功能,因此当x轴的数据非常多的时候,会自动把柱形的宽度挤的非常细,这样的交互肯定是过不去的。
因此就需要有这样一个属性:
dataZoom
想要读详细文档的同学,可以看官方文档:https://echarts.baidu.com/option.html#dataZoom
只是想要简单版的同学,看我的这个简易版本即可:
这就是一个最简单的柱形图,带横向滚动条版本。
option = {
color: ['#3398DB'],
tooltip : {
trigger: 'axis',
axisPointer : { // 坐标轴指示器,坐标轴触发有效
type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis : [
{
type : 'category',
data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisTick: {
alignWithLabel: true
}
}
],
yAxis : [
{
type : 'value'
}
],
series : [
{
name:'直接访问',
type:'bar',
barWidth: '60%',
data:[10, 52, 200, 334, 390, 330, 220]
}
],
dataZoom: {
show: true, // 为true 滚动条出现
realtime: true,
type:'slider', // 有type这个属性,滚动条在最下面,也可以不行,写y:36,这表示距离顶端36px,一般就是在图上面。
height: 20, // 表示滚动条的高度,也就是粗细
start: 20, // 表示默认展示20%~80%这一段。
end: 80
}
};