分别用brush和dataZoomSelect组件,做出框选,缩放效果,highcharts上有现成使用的方法,echart需要自己去找,特表是dataZoomSelect,在toolbox上自动开启,就可以直接使用,另外本来打算自己写个d3的方法,但是,d3上关于获取框选数据这一块比较麻烦,只能定位坐标,根据坐标计算框选的数据,计算过程略微复杂。写到一半,放弃了,主要是项目时间紧张,略略略。
1.使用dataZoomSelect
配置项说明
toolbox:{
feature : {
dataZoom : {
yAxisIndex : "none" //不启用y轴的选中
}
}
}
方法使用dispatchAction
myChart.dispatchAction({
type : "takeGlobalCursor",
key : "dataZoom",
dataZoomSelectActive : true
})
在图形缩放时触发函数
myChart.on("dataZoom",function(param){
//缩放时触发函数
})
2.使用brush
brush配置
brush: {
toolbox: ['lineX'],
xAxisIndex: 'all',
throttleType: 'debounce',
throttleDelay: 100,
outOfBrush: {
colorAlpha: 1
},
inBrush: {
colorAlpha: .3
}
}
方法使用dispatchAction
myChart.dispatchAction({
type: 'takeGlobalCursor',
key: 'brush',
brushOption: {
brushType: 'lineX'
}
});
网友评论