[英]d3 v4 brush extent Error: <rect> attribute x: Expected length, “NaN”
I am trying to follow this example: http://bl.ocks.org/mbostock/34f08d5e11952a80609169b7917d4172 我正在尝试遵循以下示例: http : //bl.ocks.org/mbostock/34f08d5e11952a80609169b7917d4172
I think the problem is setting the extent of the brushX
, following in an error for the rect overlay and selection. 我认为问题在于设置
brushX
的范围, brushX
以矩形覆盖和选择错误。
Here is my code, almost copied from the example: 这是我的代码,几乎是从示例中复制的:
var brush = d3.brushX()
.extent([0,0],[brushChart.width,brushChart.height])
.on("brush end",brushed);
context = svg.append("g")
.attr("class", "context")
.attr("transform", "translate(" + brushMargin.left + "," + brushMargin.top + ")");
context.append("g")
.attr("class", "brush")
.call(brush) //this throws errors
the errors are at the line "call(brush): 错误位于“ call(brush)”行:
I already tried to select the rect and add the values like in this example . 我已经尝试选择rect并添加此示例中的值。
The initialization of your brush contains an error. 画笔的初始化包含错误。 When calling
brush.extent()
you need to specify an array of points, ie an array of arrays (nested array): 当调用
brush.extent()
你需要指定点的数组 ,即数组的数组(嵌套数组):
# brush .
# 刷 。 extent ([ extent ]) <>
范围 ([ 范围 ]) <>
If extent is specified, sets the brushable extent to the specified array of points [[ x0, y0 ], [ x1, y1 ]]
如果指定了范围,则将可刷范围设置为指定的点数组[[ x0,y0 ],[ x1,y1 ]]
Thus, your intialization becomes 这样,您的初始化就变成了
var brush = d3.brushX()
.extent([[0,0],[brushChart.width,brushChart.height]]) // [[x0,y0], [x1,y1]]
.on("brush end",brushed);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.