echart 框选_ECharts 添加选框事件

events.brush   |   Event

选框添加事件。即发出 brush action 得到的事件。

events.brushselected   |   Event

对外通知当前选中了什么。

这个事件,在 setOption 时不会发出,在其他的 dispatchAction 时,或者用户在界面中创建、删除、修改选框时会发出。

事件参数内容为:{

type: 'brushselected',

batch: [

{

brushIndex: number // brush 组件的id,大多数情况只使用一个 brush 组件,所以不必理会。

selected: [ // 每个系列被选中的项。

// 注意,如果某个系列不支持 brush,但是还是会在这里出现对应的项。

// 也就是说,selected 可以使用 seriesIndex 来直接找到对应的项。

{ // series 0 被选中的项

seriesIndex: number,

dataIndex: [ 3, 6, 12, 23 ] // 用这些 dataIndex,可以去原始数据中找到真正的值。

},

{ // series 1 被选中的项

seriesIndex: number,

dataIndex: []

},

...

]

},

...

]

}

事件使用方式例如:var dataBySeries = [

[ 12, 23, 54, 6 ], // series 0 的数据

[ 34, 34433, 2223, 21122, 1232, 34 ] // series 1 的数据

];

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; // 统计选中项的数据值的和

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); // 用某种方式输出统计值。

});

如果想避免此事件频繁触发,可以使用 brush.throttleType。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值