1

次の構造の JSON リストがあります。

[
    {'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要素を接続しようとしています。AJAX リクエストは正しく機能しますが、.svgxyError: 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。なぜこれが起こっているのか誰にも分かりますか?

4

1 に答える 1

0

範囲が適切に指定されていない場合、スケールは空のオブジェクトを返します。たとえば、次の両方のスケールは{}、任意の値に対して呼び出されると返されます。

d3.scale.linear.domain([0, 1]).range([0, undefined])
d3.scale.linear.domain([0, 1]).range([0, NaN])

したがって、実行時に明確に定義されていますかheight?width

于 2013-02-11T09:38:35.390 に答える