Highcharts包装函数'
highcharts wrapper function for 'drag'
我试图为'拖动'编写包装器函数,以便当我单击鼠标并拖动鼠标时,我可以获得xAxis上选定区域的最小/最大值。当我尝试以下操作时,我可以看到e是一个MouseEvent,但是,我无法看到e.min和e.max(它们是未定义的)。
Highcharts.wrap(Highcharts.Pointer.prototype, "drag", function(p, e) {
console.log('drag started');
console.log(e);
console.log(e.min, e.max);
p.call(this, e);
});
有人知道有一种方法可以在xAxis上获得选定区域的边界吗?
非常感谢!
你可以这样做:
JSFiddle联系
var axisMin = -1, axisMax = -1;
$(function () {
Highcharts.wrap(Highcharts.Pointer.prototype, "dragStart", function(p, e) {
console.log('drag started');
p.apply(this, Array.prototype.slice.call(arguments, 1));
// the dragStart function sets this.mouseDownX for you
// documentation for Axis#toValue() function is here:
// http://api.highcharts.com/highcharts#Axis.toValue
axisMin = this.chart.xAxis[0].toValue(this.mouseDownX, 0);
});
Highcharts.wrap(Highcharts.Pointer.prototype, "drag", function(p, e) {
// e.chartX represents the pixel position of the mouse pointer in the chart
axisMax = this.chart.xAxis[0].toValue(e.chartX, 0);
console.log('' + new Date(axisMin) + ' to ' + new Date(axisMax));
p.apply(this, Array.prototype.slice.call(arguments, 1));
});
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=usdeur.json&callback=?', function (data) {
$('#container').highcharts({
chart: {
zoomType: 'x'
},
xAxis: {
type: 'datetime'
},
series: [{
data: data
}]
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.src.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
相关文章:
- 如何将函数包装在函数中以避免代码重复
- 尽管函数包装,但值在循环中未闭合
- 将同步函数包装到承诺中的最佳方法是什么?
- 计算三角形面积-作为变量工作,但不作为函数包装
- 如何将回调函数包装在其他回调函数中并从中调用
- 我可以在这个例子中立即调用我的函数,而不是通过匿名函数包装它吗?
- 使用自执行函数包装命名空间
- 有人可以在 JavaScript 中解释这种函数包装语法吗?
- 使用 Jasmine 测试 JavaScript 函数包装在 jQuery 中
- 将全局函数包装在 (function($){ }(jQuery) 中
- 如何将纯函数包装到构造函数中
- 为什么这个由Typescript生成的JavaScript构造函数包装了一个立即调用的函数
- 将方法名称作为回调传递VS.用烦人的函数包装它
- 为什么函数包装不隐藏javascript中未调用的函数对象
- 什么'匿名函数包装器和javascript中的新函数包装器之间的区别
- 如何将EasleJS库中的MouseEvent构造函数包装在GWT中?
- chrome.tab .create函数包装器,为什么不工作
- 将在其他地方定义的异步函数包装在回调中
- 为什么有两种不同的角函数包装方法,哪一种最好?
- 是否有一种方法可以将jquery函数包装到对象中?