[英]Drag function not working for d3
I have a drag behavior that looks like the following: 我有一个拖动行为,如下所示:
var boxDrag = d3.behavior.drag()
.origin(function (d) {
return d;
})
.on("drag", drawBox);
function drawBox( /*d*/ ) {
console.log("asdf");
}
It's only a temporary skeleton, and yet it seems to be pulling up some errors about undefined x's and such. 它只是一个临时骨架,但似乎在拉扯一些有关未定义x等的错误。
Errors 错误
Here's the full code: http://jsfiddle.net/gamea12/5zsj853h/ 这是完整的代码: http : //jsfiddle.net/gamea12/5zsj853h/
In your fiddle, you have: 在您的小提琴中,您有:
var boxDrag = d3.behavior.drag()
.origin(function (d) {
return d;
})
.on("drag", drawBox);
However, in this case, d
is undefined, which is causing your error. 但是,在这种情况下, d
是未定义的,这会导致您出错。 Changing this to: 更改为:
var boxDrag = d3.behavior.drag()
.origin(function (d) {
return this;
})
.on("drag", drawBox);
Should fix the problem for you. 应该为您解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.