多个series时,柱形图点击阴影部分获取对应的数据
配置项如下
option = {
title: {
text: 'Awesome Chart'
},
xAxis: {
data: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
},
tooltip: {
show: true,
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
yAxis: {},
series: [{
type: 'bar',
name: '第一个系列的柱子',
data: [220, 182, 191, 234, 290, 330, 310]
}, {
type: 'bar',
name: '第二个系列的柱子',
data: [20, 2, 432, 23, 565, 13, 4]
}]
};
this.getZr().off('click');
this.getZr().on('click', params => {
const pointInPixel = [params.offsetX, params.offsetY];
if (this.containPixel('grid', pointInPixel)) {
let index = this.convertFromPixel({
seriesIndex: 0
}, pointInPixel)[0];
let res = option.series[0].data[index]; //在只有一个series的时候,点击阴影部分,获取点击部分的数据
//在存在多个series的时候,点击的时候,怎么获取,点击部分的数据,是哪个series的数据
}
})