博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
echarts重写图例点击事件
阅读量:4157 次
发布时间:2019-05-26

本文共 1638 字,大约阅读时间需要 5 分钟。

echarts version: 3.1.2

修改图例点击事件样例代码:

  • 当第一次点击图例时,只显示点击的图例。
  • 当还剩一个图例被取消选中后,自动全选中所有图例。
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);            }        }    });

转载地址:http://rzkxi.baihongyu.com/

你可能感兴趣的文章
Ribbon界面图标可以直接用PNG做透明图标
查看>>
向其他软件窗口、控件发送消息的方法
查看>>
word或者pdf文件全部保存为图片的方法
查看>>
VS2010下SQLite3生成lib库文件
查看>>
sqlite3的helloworld
查看>>
MFC下支持中文的SQLite3封装类使用
查看>>
简单高效的多线程日志类
查看>>
研华USB4711A采集卡高速中断模式采集总结
查看>>
从零起步CMFCToolBar用法详解
查看>>
CMFCRibbonStatusBar用法
查看>>
CMFCControlRendererInfo类的参数
查看>>
史上最详细MFC调用mapX5.02.26步骤(附地图测试GST文件)
查看>>
CMFCShellListCtrl使用方法
查看>>
mapnik的demo运行
查看>>
python支持下的mapnik安装
查看>>
milvus手册
查看>>
查看pytorch基于cuda 的哪个版本
查看>>
多目标跟踪的简单理解
查看>>
Near-Online Multi-target Tracking with Aggregated Local Flow Descriptor
查看>>
Joint Tracking and Segmentation of Multiple Targets
查看>>