[echarts] 柱形图 设置滚动条

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
        }
};

echarts通过dataZoom来控制默认显示固定条数数据:5条

xData = this.allData.map((v) => v.value);

// 默认只显示5个柱子
startValue = this.allData[0] ? this.allData[0].value: (this.allData[0] ? this.allData[0].value: 0);

endValue = this.allData[4] ? this.allData[4].value: (this.allData[this.allData.length - 1] ? this.allData[this.allData.length - 1].value: 0);


xAxis : [
        {
            type : 'category',
            data : xData ,
            axisTick: {
                alignWithLabel: true
            }
        }
    ],

dataZoom: [
          {
            type: 'slider',
            show: true,
            handleSize: 20, // 滑动条的 左右2个滑动条的大小
            height: 14, // 组件高度
            bottom: 1, // 右边的距离
            handleColor: '#ddd', // h滑动图标的颜色
            startValue: startValue,
            endValue: endValue, 
            handleStyle: { // 两侧缩放手柄的样式配置。
              borderColor: '#cacaca',
              borderWidth: '1',
              shadowBlur: 2,
              background: '#ddd',
              shadowColor: '#ddd',
            },
            backgroundColor: 'white', // 两边未选中的滑动条区域的颜色
          },
          // 下面这个属性是拖到里面
          {
            type: 'inside',
            show: true,
            start: 1,
            end: 100,
          },
        ],

在这里插入图片描述



Echarts柱形图 设置滚动条

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值