点击echart图表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轴数据

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注