Search code examples
javascriptecharts

How to get zoomed xAxis labels from eCharts?


After using dataZoom, I need to get x-axis label values from the chart. For example, here I need to get the names of days that are inside the zoom slider.

myChart.on('datazoom', (params) => {console.log(params);})

Is only giving me coordinates of start and end the zoom


Solution

  • You can't get these values from the event params but you can still get them from the chart options:

    myChart.on('datazoom', (params) => {
      var option = myChart.getOption();
      console.log(option.xAxis[0].data.slice(option.dataZoom[0].startValue, option.dataZoom[0].endValue + 1))
    })