echarts实现双x轴并且分组滚动效果

var myChart = echarts.init(document.getElementById('allOutPut1'));

var option = {
  legend: {
    itemHeight: 10, // 图例icon高度
    itemWidth: 16, // 图例icon宽度
    icon:'rect',//设置为矩形
    top:'2%',right:'10%',
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    },
    textStyle: {
      fontSize: 12
    },
  },
  grid: { top: '10%',bottom: '28%' },
  xAxis: [
    {
      type: 'category',
      axisTick:{
        show: false
      },
      axisLine:{
        show: false
      },axisLabel:{align:'center'},
      data: ['水分', '酸度', '淀粉','水分', '酸度', '淀粉','水分', '酸度', '淀粉']
    },
    {
      type: 'category',
      position: 'bottom',
      offset: 18,
      axisPointer: {
        type: 'none'
      },
      axisTick:{
        show: false
      },
      axisLine:{
        show: false
      },
      axisLabel: {
        interval:0,align: 'center'
      },
      splitLine: {           // 新增代码,设置分隔线样式
        show: true,
        lineStyle: {
          type: 'dashed',
          color: '#999',
          width: 1
        }
      },
      data: ['2021-1轮', '2021-2轮', '2021-3轮']
    }
  ],
  yAxis: {name:'%',
    type: 'value',
  },
  series: [
    {
      name: '低于工艺范围',
      type: 'bar',barWidth:'9%',xAxisIndex:0,
      color: '#569EF8',
      showBackground: true,
      backgroundStyle: {
        color: 'rgba(255, 255, 255, 0.5)'
      },
      itemStyle: {
        // 柱形图圆角,鼠标移上去效果,如果只是一个数字则说明四个参数全部设置为那么多
        normal: {
          // 柱形图圆角,初始化效果
          barBorderRadius: [15, 15, 0, 0]
        }
      },
      data: [113, 204, 210,113, 204, 210,113, 204, 210]
    },
    {
      name: '工艺要求范围',
      type: 'bar',barWidth:'9%',xAxisIndex:0,
      color:'#00FEC1',
      showBackground: true,
      backgroundStyle: {
        color: 'rgba(255, 255, 255, 0.5)'
      },
      itemStyle: {
        // 柱形图圆角,鼠标移上去效果,如果只是一个数字则说明四个参数全部设置为那么多
        normal: {
          // 柱形图圆角,初始化效果
          barBorderRadius: [15, 15, 0, 0]
        }
      },
      data: [193, 234, 310,193, 234, 310,193, 234, 310]
    },
    {
      name: '超出工艺范围',
      type: 'bar',barWidth:'9%',xAxisIndex:0,
      color:'#F3D46C',
      showBackground: true,
      backgroundStyle: {
        color: 'rgba(255, 255, 255, 0.5)'
      },
      itemStyle: {
        // 柱形图圆角,鼠标移上去效果,如果只是一个数字则说明四个参数全部设置为那么多
        normal: {
          // 柱形图圆角,初始化效果
          barBorderRadius: [15, 15, 0, 0]
        }
      },
      data: [182, 234, 290,182, 234, 290,182, 234, 290]
    },
  ],
  dataZoom: [//给x轴设置滚动条
    {
      start:0,//默认为0
      end: 100,//默认为100
      type: 'slider',
      show: true,
      xAxisIndex: [0,1],
      handleSize: 0,//滑动条的 左右2个滑动条的大小
      height: 5,//组件高度
      left: 30, //左边的距离
      right: 60,//右边的距离
      bottom: 25,//右边的距离
      handleColor: '#ddd',//h滑动图标的颜色
      handleStyle: {
        borderColor: "#cacaca",
        borderWidth: "1",
        shadowBlur: 2,
        background: "#ddd",
        shadowColor: "#ddd",
      },
      fillerColor: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
        //给颜色设置渐变色 前面4个参数,给第一个设置1,第四个设置0 ,就是水平渐变
        //给第一个设置0,第四个设置1,就是垂直渐变
        offset: 0,
        color: '#E6E6E6'
      }, {
        offset: 1,
        color: '#E6E6E6'
      }]),
      backgroundColor: '#F8F8F8',//两边未选中的滑动条区域的颜色
      showDataShadow: false,//是否显示数据阴影 默认auto
      showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
      handleIcon: 'M-292,322.2c-3.2,0-6.4-0.6-9.3-1.9c-2.9-1.2-5.4-2.9-7.6-5.1s-3.9-4.8-5.1-7.6c-1.3-3-1.9-6.1-1.9-9.3c0-3.2,0.6-6.4,1.9-9.3c1.2-2.9,2.9-5.4,5.1-7.6s4.8-3.9,7.6-5.1c3-1.3,6.1-1.9,9.3-1.9c3.2,0,6.4,0.6,9.3,1.9c2.9,1.2,5.4,2.9,7.6,5.1s3.9,4.8,5.1,7.6c1.3,3,1.9,6.1,1.9,9.3c0,3.2-0.6,6.4-1.9,9.3c-1.2,2.9-2.9,5.4-5.1,7.6s-4.8,3.9-7.6,5.1C-285.6,321.5-288.8,322.2-292,322.2z',
      filterMode: 'filter',
    },
    //下面这个属性是里面拖到
    {
      type: 'inside',
      show: true,
      xAxisIndex: [0],
      start: 0,//默认为1
      end: 100,//默认为100
    },
  ]
}
// 使用刚指定的配置项和数据显示图表
myChart.setOption(option);
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值