2013-06-29 26 views
1

所以我用代碼關閉的這個..創建散點基於

http://bl.ocks.org/mbostock/3884955

從本質上講,我試圖做的是在每一個數據點我要添加一個圓圈。任何幫助將不勝感激看到我不知道從哪裏開始。

這是我的代碼到目前爲止:它在我使用單行時起作用。

var circlegroup = focus.append("g") 
circlegroup.attr("clip-path", "url(#clip)") 
circlegroup.selectAll('.dot') 
    .data(data) 
    .enter().append("circle") 
    .attr('class', 'dot') 
    .attr("cx",function(d){ return x(d.date);}) 
    .attr("cy", function(d){ return y(d.price);}) 
    .attr("r", function(d){ return 4;}) 
    .on('mouseover', function(d){ d3.select(this).attr('r', 8)}) 
    .on('mouseout', function(d){ d3.select(this).attr('r', 4)}); 

回答

0

您需要nested selections爲此。假設data是一個二維數組,你可以這樣做。

var groups = svg.selectAll("g").data(data).enter().append("g"); 
groups.data(function(d) { return d; }) 
     .enter() 
     .append("circle") 
     // set attributes 
+0

謝謝,仍然無法得到它。還有什麼可以在那裏如果我想在這個圖表上的數據點添加圓圈(http://bl.ocks.org/mbostock/3884955)。另外我還需要設置x和y座標,現在沒有任何圓圈出現。 d3對我來說還是很新的,我很困惑。謝謝 – nleazer