Search code examples
javascriptzoomingecharts

echarts 4.3.0 datazoom event not detected


I'm not able to detect the datazoom event when for a chart with series type graph, with roam enabled. This is for eCharts 4.3.0 but I will be testing previous versions to see if it's a regression.

Options passed in:

setup.options = {
  title: {
    top: 'bottom',
    left: 'right'
  },
  animation: false,
  tooltip: {
    trigger: 'item',
    position: 'right',
    confine: true,
    backgroundColor: 'transparent',
    padding: [40, 0, 0, 0],
    enterable: false,
    formatter: function(item) {
      return 'Click for more';
    }
  },
  series : [
    {
      name: '###',
      type: 'graph',
      layout: 'force',
      force: {
        repulsion: 95,
        gravity: 0.015,
        edgeLength: 40,
        layoutAnimation: false
      },
      roam: true,
      draggable: true,
      data: setup.nodes,
      links: setup.links,
      focusNodeAdjacency: true,
      itemStyle: {
        normal: {
          borderColor: '#fff',
          borderWidth: 1,
          shadowBlur: 10,
          shadowColor: 'rgba(0, 0, 0, 0.3)'
        }
      },
      lineStyle: {
        color: 'source',
        curveness: 0.3
      },
      emphasis: {
        lineStyle: {
          width: 10
        }
      }
    }
  ]
};



I have tried both:

// Zoom event listener
(viz.chart).on('datazoom', function(e) {
  console.log('zoomed');
  console.log(e);
});

and:

// Zoom event listener
(viz.chart).on('dataZoom', function(e) {
  console.log('zoomed');
  console.log(e);
});

I also tested adding in the datazoom toolbox component, and zoom events were not detected for that either.


Solution

  • Apparently the graph series type doesn't support dataZoom. As an alternative, you can attach a listener for graphRoam.

    myChart.on('graphRoam', function(e) {
            console.log('zoom');
    });
    

    This won't provide information about the start and end zoom state, but it will tell you whether zooming happened, and whether zoom was in or out.