echarts两个图表tooltip 联动

echarts 图表联动 柱状图 , 折线图,

完成样式

在这里插入图片描述
在这里插入图片描述

echarts 配置代码

option = {
  axisPointer: {
    link: [
      {
        xAxisIndex: [0, 1]
      }
    ]
  },
  xAxis: [
    {
      type: 'category',
      data: [
        '一',
        '二',
        '三',
        '四',
        '五',
        '六',
        '七',
        '八',
        '九',
        '十',
        '十一',
        '十二',
        '十三',
        '十四'
      ],

      gridIndex: 0
    },
    {
      type: 'category',
      data: [
        '一',
        '二',
        '三',
        '四',
        '五',
        '六',
        '七',
        '八',
        '九',
        '十',
        '十一',
        '十二',
        '十三',
        '十四'
      ],
     
      axisLabel: {
        fontSize: 14,
        color: '#333333'
      },
      gridIndex: 1
    }
  ],
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow',
      shadowStyle: {
        color: 'rgba(0, 0, 0, 0.2)'
      }
    },
   
  },
  grid: [
    {
      top: 100,
      left: 70,
      right: 150,
      bottom: 400
    },
    {
      top: 400,
      left: 70,
      right: 150,
      bottom: 50
    }
  ],
  yAxis: [
    {
      type: 'value',
      gridIndex: 0
    },
    {
      type: 'value',
      gridIndex: 1
    }
  ],
  series: [
    {
      data: [
        120, 200, 120, 200, 150, 80, 70, 110, 1130, 150, 80, 70, 110, 1130
      ],
      type: 'bar',
      showBackground: true,
      backgroundStyle: {
        color: 'rgba(180, 180, 180, 0.2)'
      },
      xAxisIndex: 0, //使用x轴的索引
      yAxisIndex: 0 //使用y轴的索引
    },
    {
      data: [
        120, 200, 150, 80, 70, 120, 200, 150, 80, 70, 110, 1130, 110, 1130
      ],
      type: 'bar',
      showBackground: true,
      backgroundStyle: {
        color: 'rgba(180, 180, 180, 0.2)'
      },
      xAxisIndex: 1, //使用x轴的索引
      yAxisIndex: 1 //使用y轴的索引
    }
  ]
};


主要代码就是
xAxisIndex
gridIndex
axisPointer: {
link: [
{
xAxisIndex: [0, 1]
}
]
},

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值