- 设置xAxis的triggerEvent属性为true
let myChart = echarts.init(document.querySelector('.right-top-echarts-line'))
let option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
xAxis: [
{
type: 'category',
data: [],
axisLabel: {
textStyle: {
color: '#ffffff',
fontSize: 8
}
},
triggerEvent: true
}
],
yAxis: [
{
type: 'value',
axisLabel: {
textStyle: {
color: '#ffffff'
}
}
}
],
series: []
}
myChart.setOption(option)
- 添加点击事件
myChart.on('dblclick', param => pieConsole.call(this, param))
function pieConsole(param) {
if (param.seriesIndex !== null && param.seriesIndex !== undefined) {
console.log('点击到了某个数据点', option.series[param.seriesIndex])
} else {
console.log('点击了x轴的某个刻度值',param.value)
}
}