1.先奉上效果圖
本來紅色部分要隨切換圖例變化的,但是我這里沒有海量數(shù)據(jù)所以沒有切換,但是自定義圖例點(diǎn)擊切換的意義就是能隨著圖例切換而改變下邊的訂單分析
2.代碼
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) {
data.orderDataType;
var selected = obj.selected;
var legend = obj.name; // 使用 legendToggleSelect Action 會(huì)重新觸發(fā) legendselectchanged Event,導(dǎo)致本函數(shù)重復(fù)運(yùn)行 // 使得 無 selected 對(duì)象
if (selected != undefined) {
if(legend=="出貨量"){
data.orderType="2"; getData();
}else{
data.orderType="1"; getData();
} if (isFirstUnSelect(selected)) {
triggerAction('legendToggleSelect', selected);
} else if (isAllUnSelected(selected)) {
triggerAction('legendSelect', selected);
}
}
});