2013-04-24 7 views
0

난 이미 내 데이터를 연결하고 다음과 같이 ID를 할당 :d3 분산 형 플롯에서 레코드의 id를 얻으려면 어떻게해야합니까?

svg.selectAll("circle").data(csv).enter().append("circle") 
        .attr("id", function(d){return "row"+d["ROW ID"];}); 

는 "ROW ID는"내 데이터의 ID를 포함하는 컬럼의 이름입니다. 이제 원 클릭 이벤트를 추가하고 현재 지점의 ID를 새 변수에 저장하여 다른 기능을 호출하고자합니다. 현재 선택된 포인트의 "ROW ID"를 얻는 방법을 알려줄 사람이 있습니까?

thx

답변

0

혹시 원했던 질문이나 오해 된 질문이 있으십니까?

svg = d3.select("svg"); 

csv = [ 
    {"row ID": "id1", 
    "x": 20, 
    "y": 30}, 
    {"row ID": "id2", 
    "x": 30, 
    "y": 50} 

] 

svg.selectAll("circle").data(csv).enter().append("circle") 
    .attr("id", function(d){return "row"+d["ROW ID"];}) 
    .attr("cx", function(d){return d.x}) 
    .attr("cy",function(d){return d.y}) 
    .attr("r",10) 
    .style("fill", "black"); 

circles = d3.selectAll("circle"); 

circles.on("click",function(d) { 
    alert(d["row ID"]); 
}) 
여기

대화 형 버전! http://tributary.io/inlet/5455132 당신은 완벽하게 내 질문을 이해

+0

많은 감사 – Amel

관련 문제