2016-12-20 4 views
0

私はソートd3チャートを描く際に問題があります。各ボタンが選択されたときに、カテゴリテキストを表示することができました。D3強制バブルチャートの描画方法

私の問題はノードのコード内にありますか?

var nodes = svg.selectAll("circle") 
     .data(data); 

    nodes.enter().append("circle") 
     .attr("Pclass", "node") 
     .attr("cx", function (d) { return d.x; }) 
     .attr("cy", function (d) { return d.y; }) 
     .attr("r", function (d) { return d.radius; }) 
     .style("fill", function (d) { return fill(d.pclass); }) 
     .on("mouseover", function (d) { showPopover.call(this, d); }) 
     .on("mouseout", function (d) { removePopovers(); }) 

    var force = d3.layout.force(); 

    draw('Pclass'); 

私のフルPlunkerはここにある:https://plnkr.co/edit/JFbPzy7nI1oAyO1Rb9wC?p=preview

+1

'.ATTR( "R"、関数(D){戻りd.radius;}).comb' d.radiusがnullをあなたが '.attr(" r "、function(d){return 10;})しようとすると'円が現れますが、うまく広がらないでしょう。 :https://plnkr.co/edit/5BTuDxXYVxyH0zx1WgJi?p=preview – mkaran

+1

'data [j] .comb'は定義されていないので、この' data [j] .radius = + data [j]のため、d.radiusはnullです。 comb/2; 'はNaNで終わります。これを見てみましょう:https://plnkr.co/edit/5BTuDxXYVxyH0zx1WgJi?p=previewここで、NAgeを使って半径を計算しています。お役に立てれば! – mkaran

+0

ありがとう!これは完璧な意味合いがあります。私がこのページをチェックする前に、答えは私の頭に浮かんだ。それは確かにコードで非常に小さなエラーでした –

答えて

1

私はこの問題を自分で考え出しました。私は悪い変数を持っていた。私は、データを変更するために必要なデータから、[J] .Nfare [j]が

for (var j = 0; j < data.length; j++) { 
     data[j].radius = +data[j].Nfare/5; 
     data[j].x = Math.random() * width; 
     data[j].y = Math.random() * height; 
    } 
関連する問題