柱形图外层增加点击事件,里层点击怎么阻止冒泡到外层点击呢 echarts

http404
  • 255

div加一个点击事件,柱形图里面某个图形点击会触发到外层,请问怎么阻止外层触发呢,echarts里面的点击事件参数里面貌似没有stopPropagation()和preventDefault()方法

`let axis = echarts.init(document.getElementById('axis'))
axis.off('click');
let option = {

xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
    type: 'value'
},
series: [{
    data: [120, 200, 150, 80, 70, 110, 130],
    type: 'bar'
}]

};
axis.on('click',function(parames){//会触发外层
console.log('当前柱形图')
})

click = () => {
console.log('外层')
}
...
<div id='axis' onClick={this.click}></div>`

122.png

回复
阅读 1.4k
1 个回答

不知道你那能不能获取到event对象,我在官网试的可以

myChart.on('click', function (params) {
    console.log(params);
    console.log( 'in|window-Event',window.event)
    console.log( 'in|Event',event)
    // window.event.cancelBubble = true;
    event.cancelBubble = true;
    console.log( 'in|cancelBubble',event.cancelBubble)
});

截屏2020-05-15 上午11.18.34.png

你知道吗?

宣传栏