2012-05-02 3 views
1

SoundCloud API에 d3.js를 사용하고 있습니다. 버블에 트랙 제목을 표시하는 버블 그래프를 만들고 싶습니다.d3.js + SoundCloud API 사용하기 - 트랙 제목을 표시해야합니다.

페이지가 "원"요소에로드되면 HTML에 표시됩니다. 하지만 왜 그들이 표시되지 않는지 잘 모르겠습니다.

및 트랙 제목을 표시하는 버블 그래프를 만들려고합니다.

내가 여기에 볼 수 있습니다 뭘하는지의 예 : http://butchershopcreative.github.com/ui-experiments/soundcloud/example/

코드는 다음과 같습니다

SC.initialize({ 
    client_id: "7kIeyF5f2ETFo1fEWKwNQ", 
    redirect_uri: "http://localhost:8000/soundcloud/example/", 
}); 

SC.get("/tracks?genres=dubstep&order=hotness", {limit: 100}, function(tracks){ 
    var svg = d3.select("#chart").append("svg") 
     .attr("width", 640) 
     .attr("height", 480); 
    var y = 500; 
    var x = 1000; 
    var circle = svg.selectAll("circle") 
     .data(tracks) // data binds information to the circles 
    .enter().append("circle").transition() // Added transitions 
     .duration(1000) 
     .delay(function(d, i) { return i * 10; }) 
     .attr("r", function(d) { return Math.sqrt(d * scale); }) 
     .style("fill", "steelblue") 
     .style("stroke","#000") 
     .style("stroke-width", "3px") 
     .attr("class", "track") 
     .attr("cx", function() { 
      return Math.random() * x;}) // produces random x position 
     .attr("cy", function() { 
      return Math.random() * y;}) // produces random y position 
     .attr("r", 50) 
     .text(function(track) { 
      console.log(track); 
      return track.title; 
     }); 
}); 
+0

I 데이터가 모든 시간을로드하지 않는 것 (비록 연결된 예에서 원을 참조 - 이것은 사운드 클라우드 API를 사용하여 문제가 될 수 있습니다). 이 질문을 올린 후 코드를 업데이트 한 적이 있습니까? 여전히 문제가 있습니까? – nrabinowitz

답변

0

문제는 당신이 텍스트의 circle 요소를 사용하고 있다는 점이다. SVG text 요소를 사용해야하며 원과 텍스트를 g 요소로 그룹화합니다.

지금처럼 ( enter()update 코드 분리) :

var bubble = svg.selectAll(".bubble") 
    .data(tracks) // data binds information to the bubbles 

bubble.enter().append("svg:g") 
    .attr("class", "bubble"); 

bubble.append("svg:circle") 
    .attr("r", function(d) { return Math.sqrt(d * scale); }) 
    .style("fill", "steelblue") 
    .style("stroke","#000") 
    .style("stroke-width", "3px") 
    .attr("class", "track") 
    .attr("cx", function() { 
    return Math.random() * x;}) // produces random x position 
    .attr("cy", function() { 
    return Math.random() * y;}) // produces random y position 
    .attr("r", 50); 

bubble.append("svg:text") 
    .text(function(track) { 
    return track.title; 
    });