2012-09-04 4 views
7

上の点を散乱させるためにラベルを追加する私はこのグラフ上の散布ポイントにラベルを追加しようとしています:http://bost.ocks.org/mike/d3/workshop/dot-chart.htmld3.js:どのようにグラフ

私はこのコードを少し変更することは働くだろうと思ったが、それはdidnの't:

svg.selectAll(".dot") 
    .append("text") 
    .text("fooLabelsOfScatterPoints"); 
+2

あなたは、この例を見てきました:HTTP ://mbostock.github.com/d3/ex/bubble.html、それはソースです:http://mbostock.github.com/d3/ex/bubble.js –

+0

マイク、あなたの例を見ると、私はタグをタグに付加するのではなく、タグにタグを追加する必要があります。私は今それを試してみるでしょう。 –

答えて

11

マイケルロビンソンが助けました。ここでは、不思議に思っている人のために

は私がやったことです:

svg.selectAll(".dot") 
    .data(data) 
    .enter().append("circle") 
    .attr("class", "dot") 
    .attr("cx", function(d) { return x(d.x); }) 
    .attr("cy", function(d) { return y(d.y); }) 
    .attr("r", 12); 

て、コメントを追加しました::

私は削除

var node = svg.selectAll("g") 
       .data(data) 
       .enter() 
       .append("g"); 

node.append("circle") 
    .attr("class", "dot") 
    .attr("cx", function(d) { return x(d.x); }) 
    .attr("cy", function(d) { return y(d.y); }) 
    .attr("r", 12); 

node.append("text") 
    .attr("x", function(d) { return x(d.x); }) 
    .attr("y", function(d) { return y(d.y); }) 
    .text("fooLabelsOfScatterPoints"); 

を私は "G" に "テキスト" のタグを追加タグを「サークル」タグに付加するのではなく、

+0

援助の喜び –

+0

@MikeRobinson私は同様の問題を抱えていますが、気泡の異なるバージョンを使用しています。スライダを動かしている間に気泡の半径が変化します。これらの気泡もテキストを追加したいのですが少し助けてください? – user2480542

0

私はノードのソリューションを試みたときに、私のデータの一部が消えたので、私はちょうど私のために働いた「ドードー」と呼ばれる新しいクラスを追加した(?):

svg.selectAll(".dot") 
    .data(data) 
.enter().append("circle") 
    .attr("class", "dot") 
    .attr("r", 3.5) 
    .attr("cx", function(d) { return x(d.time); }) 
    .attr("cy", function(d) { return y(d.place); }) 
    .style("fill", function(d) { return color(d.species); }); 

svg.selectAll(".dodo") 
    .data(data) 
.enter().append("text") 
    .attr("class", "dodo") 
    .attr("x", function(d) { return x(d.time); }) 
    .attr("y", function(d) { return y(d.place); }) 
    .attr("dx", ".71em") 
    .attr("dy", ".35em") 
    .text(function(d) { return d.name;}); 
関連する問題