1
我有以下結構的JSON列表:D3:無效屬性[對象的對象]
[
{'uid': 4, 'x': -1.2354657, 'y': -0.992893}
{'uid': 26, 'x': 0.2783682, 'y': -0.1931}
...
{'uid': 26, 'x': -0.278356, 'y': 0.082983}
]
我試圖svg:circle
元件附加到svg
在通過在x
和y
值指定的點這個清單。 AJAX請求正常工作,但我一直收到Error: Invalid value for <circle> attribute cy="[object Object]"
。
相關javascript代碼:
var svg = d3.select('#d3')
.append('svg')
.append('g')
.attr('class', 'main')
...
var x = d3.scale.linear()
.domain(d3.extent(data, function (d) {return d.x;}))
.range([0, width]);
var y = d3.scale.linear()
.domain(d3.extent(data, function (d) {return d.y;}))
.range([height, 0]);
...
svg.selectAll('.bloom')
.data(data)
.enter()
.append('g')
.attr('class', 'bloom')
.append('circle')
.attr('class', 'bloom-circle')
.attr('cx', function (d) {return x(d.x);})
.attr('cy', function (d) {return y(d.y);})
.attr('r', 10)
.style('fill', 'purple')
.style('stroke', 'white')
.style('stroke-width', '5px');
我真的不知道發生了什麼事情,因爲d3.scale.linear
應始終在其range
返回一個值。有人知道爲什麼會發生這種情況嗎?
x和y字符串或數字? – Wex 2013-02-11 19:36:36