只记录下如何获取点击标题的事件
在option的title内,设置triggerEvent为true开启点击事件监听,cursor为pointer是为了鼠标移动到标题时,看上去要可点击。
title: [
{
text: title,
triggerEvent: true, // 开启点击事件监听
cursor: 'pointer', // 鼠标移动到标题时,将其改为手指,表示可点击
left: 'center',
textStyle: {
color: '#5470c6',
fontSize: 14
}
},
{
text: '数量',
left: '5%',
top: 30,
textStyle: {
fontSize: 12,
color: '#999' // 副标题的字体颜色
}
}
]
myChart.setOption(option, true)
myChart.off('click')
// 监听 click 事件
myChart.on('click', params => {
if (params.componentType === 'title') {
// 在这里处理点击标题的事件
// 你的代码...
}
})
如果要echart的其他地方的点击事件,打印下点击事件的参数就能够清除了。