vue-echarts-dataZoom(联动)

<template>
  <el-row>
    <el-col :span="8">
      图一
      <div id="myChartOne" style="width: 550px; height: 550px"></div>
    </el-col>
    <el-col :span="8">
      图二
      <div id="myChartTwo" style="width: 550px; height: 550px"></div>
    </el-col>
    <el-col :span="8">
      图三
      <div id="myChartThree" style="width: 550px; height: 550px"></div>
    </el-col>
  </el-row>
</template>



<script>
export default {
  data() {
    return {};
  },
  mounted() {
    this.drawLine();
  },
  methods: {
    drawLine() {
      var echarts = require("echarts");
      var lineOne = echarts.init(document.getElementById("myChartOne"));
      var lineTwo = echarts.init(document.getElementById("myChartTwo"));
      var lineThree = echarts.init(document.getElementById("myChartThree"));

      var optionOne = {
        dataZoom: [
          {
            type: "slider",
          }
        ],
        xAxis: {
          scale: true,
          data: [22, 24, 26, 28, 22, 32, 34, 46, 48, 50],
        },
        yAxis: {
          scale: true,
        },
        series: [
          { type: "scatter", data: [22, 22, 26, 28, 30, 22, 34, 36, 38, 40] },
        ],
      };


      var optionTwo = {
        dataZoom: [
          {
            type: "slider",
          },
        ],
        xAxis: {
          scale: true,
          data: [22, 24, 26, 28, 22, 32, 34, 46, 48, 50],
        },
        yAxis: {
          scale: true,
        },
        series: [
          { type: "scatter", data: [22, 22, 26, 28, 30, 22, 34, 36, 38, 40] },
        ],
      };


      var optionThree = {
        dataZoom: [
          {
            type: "slider",
          }
        ],
        xAxis: {
          scale: true,
          data: [22, 24, 26, 28, 22, 32, 34, 46, 48, 50],
        },
        yAxis: {
          scale: true,
        },
        series: [
          { type: "scatter", data: [22, 22, 26, 28, 30, 22, 34, 36, 38, 40] },
        ],
      };


      lineOne.setOption(optionOne);
      lineTwo.setOption(optionTwo);
      lineThree.setOption(optionThree);


      lineOne.on("datazoom", function (params) {
   
      console.log(params);
        //获得图表数据数组下标
        var startValue = lineOne.getModel().option.dataZoom[0].startValue;
        var endValue = lineOne.getModel().option.dataZoom[0].endValue;

        // 图一联动
       //获得起止位置百分比
        var startPercentOne = lineOne.getModel().option.dataZoom[0].start;
        var endPercentOne = lineOne.getModel().option.dataZoom[0].end;


        optionTwo.dataZoom[0].start = startPercentOne;
        optionTwo.dataZoom[0].end = endPercentOne;
        lineTwo.setOption(optionTwo);


        optionThree.dataZoom[0].start = startPercentOne;
        optionThree.dataZoom[0].end = endPercentOne;
        lineThree.setOption(optionThree);
      });


      lineTwo.on("datazoom", function (params) {
        // 图二联动
        //获得起止位置百分比
        var startPercentTwo = lineTwo.getModel().option.dataZoom[0].start;
        var endPercentTwo = lineTwo.getModel().option.dataZoom[0].end;

        optionOne.dataZoom[0].start = startPercentTwo;
        console.log(startPercentTwo, optionOne.dataZoom[0].start, "图二联动");
        optionOne.dataZoom[0].end = endPercentTwo;
        lineOne.setOption(optionOne);


        optionThree.dataZoom[0].start = startPercentTwo;
        optionThree.dataZoom[0].end = endPercentTwo;
        lineThree.setOption(optionThree);
      });

      lineThree.on("datazoom", function (params) {
        // 图三联动
        //获得起止位置百分比
        var startPercentThree = lineThree.getModel().option.dataZoom[0].start;
        var endPercentThree = lineThree.getModel().option.dataZoom[0].end;

        optionTwo.dataZoom[0].start = startPercentThree;
        optionTwo.dataZoom[0].end = endPercentThree;
        lineTwo.setOption(optionTwo);

        optionOne.dataZoom[0].start = startPercentThree;
        optionOne.dataZoom[0].end = endPercentThree;
        lineOne.setOption(optionOne);
      });
    },
  },
};
</script>


<style>
</style>

 实现效果:当图一的dataZoom发生变化,图二以及图三的dataZoom也会变化。同理可得,图二的dataZoom发生变化,图一以及图三的dataZoom也会发生变化。同理可得,图三也是如此。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值