2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > echarts中重写图例点击事件 阻止默认事件

echarts中重写图例点击事件 阻止默认事件

时间:2022-10-05 12:03:35

相关推荐

echarts中重写图例点击事件 阻止默认事件

1.取消全部图例点击事件

*只需添加一个属性即可

legend: {selectedMode:false }

2.重写图例点击事件,示例为 点哪个图例显示哪条折线

*获取点击图例对应图例数组中的index,在series中替换数据即可

chart.on('legendselectchanged', function (params) {let legend = params.name;const index = nameList.findIndex(item => item == legend);option.series[4] = addOption[index];chart.dispatchAction({type: 'legendSelect',name: params.name});chart.setOption(option);});

我的addOption定义为

var addOption = [{name: nameList[0],type: 'line',data: aList,},{name: nameList[1],type: 'line',data: bList,},{name: nameList[2],type: 'line',data: cList,},{name: nameList[3],type: 'line',data: dList,}];

原效果图

改后效果图(图例只控制折线图,且点哪个显示哪个,默认显示优秀)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。