点击echart图表的x轴线或者x轴坐标,获取x轴的数据,高亮显示x轴坐标。

[echarts] 点击x轴获取x轴数据, 点击x轴线获取x轴数据_高亮显示

//设置x轴坐标可以点击
	xAxis: [{
		triggerEvent: true,
	    axisLabel: {
	    	color: function (value, index) {
	   			return value == time ? '#21aced' : '#fff';
	    	},
	    	clickable: true,
	    },
	}],
let time = ""
      //点击x轴线
      myChart.getZr().on('click', params => {
        const pointInPixel = [params.offsetX, params.offsetY]
        if (myChart.containPixel('grid', pointInPixel)) {
          const xIndex = myChart.convertFromPixel({ seriesIndex: 0 }, [params.offsetX, params.offsetY])[0]
          time = option.xAxis[0].data[xIndex]
          myChart.resize();
          console.log(time)
        }
      })

      //点击x轴坐标
      myChart.on('click', 'xAxis.category', function (params, node) {
        time = params.value
        myChart.resize();
        console.log(time)
      });

参考:

Echarts点击x轴获取x轴数据