1,添加點(diǎn)擊事件,在myChart.setOption(option)下添加myChart.on('click',function(params){})即可
option = {
color: ['#3398DB'],
tooltip: {
trigger: 'axis',
axisPointer: { // 坐標(biāo)軸指示器,坐標(biāo)軸觸發(fā)有效
type: 'shadow' // 默認(rèn)為直線,可選為:'line' | 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisTick: {
alignWithLabel: true
}
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
name: '直接訪問',
type: 'bar',
barWidth: '60%',
data: [10, 52, 200, 334, 390, 330, 220]
}
]
};
myChart.on('click',function(params){
alert(1)
})

2,添加完了之后,當(dāng)切換條件查詢echart時(shí)可能出現(xiàn)多次觸發(fā)點(diǎn)擊事件,向后臺發(fā)多次請求
這時(shí),只需在myChart.setOption(option)前面添加一行代碼
myChart.off('click') 來解除綁定的點(diǎn)擊事件即可