【问题标题】:Only trigger pan-end event with amCharts仅使用 amCharts 触发 pan-end 事件
【发布时间】:2016-07-28 11:21:20
【问题描述】:
【问题讨论】:
标签:
javascript
amcharts
panning
【解决方案1】:
没有专门的活动。但是,您可以通过使用 JavaScript 通用 mouseup/touchend 事件来实现该功能,以捕捉平移结束的时间。即:
"listeners": [{
/**
* rendered event
* we'll use it to set up custom mouse events as well as
* pre-zoom the chart
*/
"event": "rendered",
"method": function(e) {
// add mouseup events
e.chart.chartDiv.addEventListener("mouseup", handleEnd);
e.chart.chartDiv.addEventListener("touchend", handleEnd);
// function that handles pan end (mouse button released or touch ends)
function handleEnd() {
// check if there was an previous zoom event
if (e.chart.lastZoomedEvent === undefined)
return;
// do what we need to do with it
// ...
console.log(e.chart.lastZoomedEvent);
// reset
e.chart.lastZoomedEvent = undefined;
}
// pre-zoom the chart
e.chart.zoomToIndexes(
e.chart.dataProvider.length - 40,
e.chart.dataProvider.length - 1);
}
}, {
/**
* zoomed event
* we'll use it to track pan/zoom
*/
"event": "zoomed",
"method": function(e) {
// log last zoomed event
e.chart.lastZoomedEvent = e;
}
}]
这是working demo。