{"action":"created","issue":{"url":"https://api.github.com/repos/ecomfe/echarts/issues/1081","repository_url":"https://api.github.com/repos/ecomfe/echarts","labels_url":"https://api.github.com/repos/ecomfe/echarts/issues/1081/labels{/name}","comments_url":"https://api.github.com/repos/ecomfe/echarts/issues/1081/comments","events_url":"https://api.github.com/repos/ecomfe/echarts/issues/1081/events","html_url":"https://github.com/ecomfe/echarts/issues/1081","id":52809724,"number":1081,"title":"echarts如何重写某个图例项的点击事件，这个能实现吗","user":{"login":"panh","id":5680220,"avatar_url":"https://avatars.githubusercontent.com/u/5680220?v=3","gravatar_id":"","url":"https://api.github.com/users/panh","html_url":"https://github.com/panh","followers_url":"https://api.github.com/users/panh/followers","following_url":"https://api.github.com/users/panh/following{/other_user}","gists_url":"https://api.github.com/users/panh/gists{/gist_id}","starred_url":"https://api.github.com/users/panh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/panh/subscriptions","organizations_url":"https://api.github.com/users/panh/orgs","repos_url":"https://api.github.com/users/panh/repos","events_url":"https://api.github.com/users/panh/events{/privacy}","received_events_url":"https://api.github.com/users/panh/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-12-24T10:12:38Z","updated_at":"2016-03-09T06:24:07Z","closed_at":"2014-12-26T10:31:03Z","body":"如题，想要实现点击图例项，重新从后台获取选择项的数据，前台展示"},"comment":{"url":"https://api.github.com/repos/ecomfe/echarts/issues/comments/194137225","html_url":"https://github.com/ecomfe/echarts/issues/1081#issuecomment-194137225","issue_url":"https://api.github.com/repos/ecomfe/echarts/issues/1081","id":194137225,"user":{"login":"yantze","id":2226423,"avatar_url":"https://avatars.githubusercontent.com/u/2226423?v=3","gravatar_id":"","url":"https://api.github.com/users/yantze","html_url":"https://github.com/yantze","followers_url":"https://api.github.com/users/yantze/followers","following_url":"https://api.github.com/users/yantze/following{/other_user}","gists_url":"https://api.github.com/users/yantze/gists{/gist_id}","starred_url":"https://api.github.com/users/yantze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yantze/subscriptions","organizations_url":"https://api.github.com/users/yantze/orgs","repos_url":"https://api.github.com/users/yantze/repos","events_url":"https://api.github.com/users/yantze/events{/privacy}","received_events_url":"https://api.github.com/users/yantze/received_events","type":"User","site_admin":false},"created_at":"2016-03-09T06:24:07Z","updated_at":"2016-03-09T06:24:07Z","body":"修改图例点击事件样例代码：\r\n1. 当第一次点击图例时，只显示点击的图例。\r\n2. 当还剩一个图例被`取消选中`后，自动全选中所有图例。\r\n\r\n```javascript\r\n  var triggerAction = function(action, selected) {\r\n        legend = [];\r\n\r\n        for ( name in selected) {\r\n            if (selected.hasOwnProperty(name)) {\r\n                legend.push({name: name});\r\n            }\r\n        }\r\n\r\n        myChart.dispatchAction({\r\n            type: action,\r\n            batch: legend\r\n        });\r\n    };\r\n\r\n    var isFirstUnSelect = function(selected) {\r\n\r\n        var unSelectedCount = 0;\r\n        for ( name in selected) {\r\n            if (!selected.hasOwnProperty(name)) {\r\n                continue;\r\n            }\r\n\r\n            if (selected[name] == false) {\r\n                ++unSelectedCount;\r\n            }\r\n        }\r\n        return unSelectedCount==1;\r\n    };\r\n\r\n    var isAllUnSelected = function(selected) {\r\n        var selectedCount = 0;\r\n        for ( name in selected) {\r\n            if (!selected.hasOwnProperty(name)) {\r\n                continue;\r\n            }\r\n\r\n            // 所有 selected Object 里面 true 代表 selected， false 代表 unselected\r\n            if (selected[name] == true) {\r\n                ++selectedCount;\r\n            }\r\n        }\r\n        return selectedCount==0;\r\n    };\r\n\r\n    myChart.on('legendselectchanged', function(obj) {\r\n        var selected = obj.selected;\r\n        var legend = obj.name;\r\n\r\n        // 使用 legendToggleSelect Action 会重新触发 legendselectchanged Event，导致本函数重复运行。\r\n        // 使得 无 selected 对象\r\n        if (selected != undefined) {\r\n\r\n            if (isFirstUnSelect(selected)) {\r\n                triggerAction('legendToggleSelect', selected);\r\n            } else if (isAllUnSelected(selected)) {\r\n                triggerAction('legendSelect', selected);\r\n\r\n            }\r\n        }\r\n\r\n    });\r\n```"}}