2016-10-04 34 views
0

我試圖遵循這個例子:http://bl.ocks.org/mbostock/34f08d5e11952a80609169b7917d4172D3 V4刷程度錯誤:<rect>屬性X:預期長度,「南」

我認爲問題是設置brushX的程度,在用於錯誤以下矩形覆蓋和選擇。

這裏是我的代碼,幾乎從示例複製:

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 

的錯誤是在該行「調用(刷):

errors

我已經嘗試選擇矩形並添加如this example中的值

+0

如何計算'brushChart.width'和高度?也許你可以提供一個jsfiddle或plunkr? – Oleg

+0

我將它設置在一個變量中:var brushChart = {width:500,height:500};我儘快提供一個jsfiddle。 – Dario

+0

當調用'parseInt()'或'parseFloa()t'時,'NaN'在JavaScript中返回,並且無法將字符串轉換爲數字。你的錯誤基本上是說,嘿我期待一個數字('長度'),但得到了'NaN',所以在計算'長度'時,你必須傳遞一個無效的字符串不能被分析成一個數字。 – Ryan

回答

2

刷子的初始化包含錯誤當調用brush.extent(),你需要指定一個陣列點,即數組的數組(嵌套數組):

#brush.extent([extent]) <>

If extent is specified, sets the brushable extent to the specified array of points [[x0, y0], [x1, y1]]

因此,您intialization變得

var brush = d3.brushX() 
       .extent([[0,0],[brushChart.width,brushChart.height]]) // [[x0,y0], [x1,y1]] 
       .on("brush end",brushed); 
+0

非常感謝你,令人難以置信的是我怎麼錯過了這兩個例子和兩個從文件..有時不做複製和粘貼沒有幫助.. :) – Dario

相關問題