echarts 多个图表滚动轴联动

一、封装的文件echarts_link.js

export function echartslink(ele, node) {
  // ele 被操作图表, node 要被改变的图表[]
  ele.on('datazoom', function (params) {
  // console.log(ele.getOption())
  // 获得起止位置百分比
  const startPercent = ele.getOption().dataZoom[0].start
  const endPercent = ele.getOption().dataZoom[0].end
  node.forEach(ment => {
    let option = ment.getOption()
    option.dataZoom[0].start = startPercent
    option.dataZoom[0].end = endPercent
    ment.setOption(option)
  })
 })
}

二、使用

// 引入
import { echartslink } from '../../units/echarts_link'
echartslink(this.linebox, [this.lineboxs,this.lineboxs2])
// this.linebox被拖动的图标 要被改变的图表[this.lineboxs,this.lineboxs2]

非常好用
采纳请点赞谢谢!!

你可能感兴趣的:(echarts 多个图表滚动轴联动)