echarts自定义图例的点击事件
2018-03-27 16:30
337 查看
修改图例点击事件样例代码:
当第一次点击图例时,只显示点击的图例。当还剩一个图例被取消选中后,自动全选中所有图例。
var triggerAction = function(action, selected) { legend = []; for ( name in selected) { if (selected.hasOwnProperty(name)) { legend.push({name: name}); } } myChart.dispatchAction({ type: action, batch: legend }); }; var isFirstUnSelect = function(selected) { var unSelectedCount = 0; for ( name in selected) { if (!selected.hasOwnProperty(name)) { continue; } if (selected[name] == false) { ++unSelectedCount; } } return unSelectedCount==1; }; var isAllUnSelected = function(selected) { var selectedCount = 0; for ( name in selected) { if (!selected.hasOwnProperty(name)) { continue; } // 所有 selected Object 里面 true 代表 selected, false 代表 unselected if (selected[name] == true) { ++selectedCount; } } return selectedCount==0; }; myChart.on('legendselectchanged', function(obj) { var selected = obj.selected; var legend = obj.name; // 使用 legendToggleSelect Action 会重新触发 legendselectchanged Event,导致本函数重复运行 // 使得 无 selected 对象 if (selected != undefined) { if (isFirstUnSelect(selected)) { triggerAction('legendToggleSelect', selected); } else if (isAllUnSelected(selected)) { triggerAction('legendSelect', selected); } } });
相关文章推荐
- Echarts之柱状图获取点击柱子事件&自定义柱子颜色&类目轴纵向排列
- 自定义图例点击事件
- 自定义图例点击事件
- echarts重写图例点击事件
- echarts 取消图例上的点击事件和图表上鼠标滑过点击事件
- echarts 图例 legend 取消点击事件
- echarts 取消图例上的点击事件和图表上鼠标滑过点击事件
- echarts 取消图例上的点击事件和图表上鼠标滑过点击事件
- 自定义TextView设置边框与背景颜色添加点击事件,点击更改随机数与背景
- Android自定义Notification添加点击事件
- ListView使用自定义适配器的情况下实现适配器的文本和图标控件点击事件执行Activity界面中的方法
- iOS 自定义百度地图大头针点击事件
- 自定义CheckBox解决label点击事件触发两次问题
- 自定义view随机数点击事件
- Qt-Qlabel 自定义鼠标点击事件以及文本样式效果设计
- 自定义view中控件的点击事件
- 自定义UITableViewCell 上按钮点击事件处理
- android 自定义listview无法响应点击事件OnItemClickListener
- RecyclerView基础-数据适配、自定义分割线、上拉加载、下拉加载、item点击事件
- echarts 点击事件