보로 노이 지역과 관련된 도시 이름과 인구를 표시하고 싶습니다. 그러나 보 로노이 영역을 어떻게 만들었는지에 따라 좌표 데이터를 보내고 모든 도면을 작동 시키거나 더 많은 데이터를 보내야하며 보로 노이 영역 중 어느 것도 그려지지 않았습니다 (b/c, 좌표 데이터 및 적어도 배열 또는 개체 내에서 지정하는 방법을 모르겠다면, voronois를 만들 때). 툴팁에 대한 정적 데이터 또는 관련성없는 데이터를 입력 할 수 있습니다 (아래에서 설명했듯이).하지만 실제 데이터 셋의 데이터는 입력 할 수 없습니다.보로 노이 폴리곤 위로 가져갈 때 정보 표시 (D3.js에서)
var tooltip = d3.select("body")
.append("div")
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden")
.text("a simple tooltip");
var voronoi = d3.geom.voronoi()
.clipExtent([[0, 0], [w, h]]);
d3.csv("us-cities1.csv", function(d) {
return [projection([+d.lon, +d.lat])[0], projection([+d.lon, +d.lat])[1]];
}, function(error, rows) {
vertices = rows;
drawV(vertices);
}
);
function polygon(d) {
return "M" + d.join("L") + "Z";
}
function drawV(d) {
svg.append("g")
.selectAll("path")
.data(voronoi(d), polygon)
.enter().append("path")
.attr("class", "test")
.attr("d", polygon)
.attr("id", function(d, i){return i;})
.on("mouseover", function(){return tooltip.style("visibility", "visible");})
.on("mousemove", function(){return tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px").text((this).id);})
.on("mouseout", function(){return tooltip.style("visibility", "hidden");});
svg.selectAll("circle")
.data(d)
.enter().append("circle")
.attr("class", "city")
.attr("transform", function(d) { return "translate(" + d + ")"; })
.attr("r", 2);
}
당신은 (보로 노이에 대한 x와 y에 대한 접근 기능을 지정 ([여기] https://github.com/mbostock/d3/wiki/Voronoi-을 볼 수 있습니다 찾을 수 있습니다 Geom # wiki-x)). 이를 통해 좌표를 추출하는 f}을 지정할 수 있으며 다른 데이터를 가질 수 있습니다. –
나는 분명히 그 구문을 어떻게 사용하는지 이해하지 못하고있다. 빠른 예제를 제공 할 수 있습니까? 내 데이터에는 "순위", "장소", "인구", "위도"및 "경도"헤더가 있습니다. 많은 변형을 시도했지만 가장 이해가가능한 것으로 생각되는 것은 다음과 같습니다. d3.csv ("us-cities1.csv", function (d) { \t svg.append ("g") .selectAll ("path") .data (voronoi.x (+ d.lon) .y (+ d.lat), polygon) .... – NickSilhacek
작동해야하지만 마우스 오버 기능에서 추가해야합니다 마우스 오버 기능의 첫 번째 매개 변수로 자동 전달되는 데이터에 액세스하는 코드와 툴팁 텍스트를 설정하는 코드. 자습서 [here] (http://chimera.labs.oreilly.com/books/1230000000345/ch10. html # _binding_event_listeners) 웹에서 Scott Murray의 대화 형 데이터 시각화 – AmeliaBR