W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
events.brush | Event
選框添加事件。即發(fā)出 brush action 得到的事件。
events.brushselected | Event
對外通知當(dāng)前選中了什么。
參見 區(qū)域選擇。
這個事件,在 setOption 時不會發(fā)出,在其他的 dispatchAction 時,或者用戶在界面中創(chuàng)建、刪除、修改選框時會發(fā)出。
事件參數(shù)內(nèi)容為:
{
type: 'brushselected',
batch: [
{
brushIndex: number // brush 組件的id,大多數(shù)情況只使用一個 brush 組件,所以不必理會。
selected: [ // 每個系列被選中的項。
// 注意,如果某個系列不支持 brush,但是還是會在這里出現(xiàn)對應(yīng)的項。
// 也就是說,selected 可以使用 seriesIndex 來直接找到對應(yīng)的項。
{ // series 0 被選中的項
seriesIndex: number,
dataIndex: [ 3, 6, 12, 23 ] // 用這些 dataIndex,可以去原始數(shù)據(jù)中找到真正的值。
},
{ // series 1 被選中的項
seriesIndex: number,
dataIndex: []
},
...
]
},
...
]
}
事件使用方式例如:
var dataBySeries = [
[ 12, 23, 54, 6 ], // series 0 的數(shù)據(jù)
[ 34, 34433, 2223, 21122, 1232, 34 ] // series 1 的數(shù)據(jù)
];
chart.setOption({
...,
brush: {
...
},
series: [
{ // series 0
data: dataBySeries[0]
},
{ // series 1
data: dataBySeries[1]
}
]
});
chart.on('brushSelected', function (params) {
var brushComponent = params.batch[0];
var sum = 0; // 統(tǒng)計選中項的數(shù)據(jù)值的和
for (var sIdx = 0; sIdx < brushComponent.selected.length; sIdx++) {
// 對于每個 series:
var dataIndices = brushComponent.selected[sIdx].dataIndex;
for (var i = 0; i < dataIndices.length; i++) {
var dataIndex = dataIndices[i];
sum += dataBySeries[sIdx][dataIndex];
}
}
console.log(sum); // 用某種方式輸出統(tǒng)計值。
});
如果想避免此事件頻繁觸發(fā),可以使用 brush.throttleType。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: