今天有个奇怪的需求,需要点击echart图表内容切换数据,所以百度研究了下相关的逻辑,现记个小记:
var myChart = echarts.init(document.getElementById("cardEchart"));
myChart.getZr().on("mouseup", function (param) {
let pointInPixel = [param.offsetX, param.offsetY]
let pointInGrid = myChart.convertFromPixel({ seriesIndex: 0 }, pointInPixel);
let y_index = pointInGrid[1];
console.log('坐标轴:');
console.log(pointInGrid);
var op=myChart.getOption();
console.log('x,y数据:');
console.log(op.xAxis);
console.log(op.yAxis);
console.log(op.yAxis[0].data[y_index]);
});