이 example을 사용하여 누적 막 대형 차트를 만듭니다. 차트가 작동하고 렌더링되지만 마우스 오버 레이블을 추가 할 수 없습니다. D3에 누적 막대 그래프에 제목을 추가 할 수 없습니다
I이 시도
...DATE.selectAll("rect")
.data(function(d) { return d.ages; })
.enter().append("rect")
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.y1); })
.attr("height", function(d) { return y(d.y0) - y(d.y1); })
.style("fill", function(d) { return color(d.name); });
.append("svg:title")
.text(functino(d){return "foo"});
하지만 이것을 .append("svg:title...
를 추가 한 후, 그래프는 렌더링을 중지. .style("fill...
행을 제거하면 그래프가 렌더링되지만 누적되지 않으며 마우스 오버 기능이 없습니다.
툴팁 경로를 사용해 보았습니다. (Source)
.on("mouseover", function() { tooltip.style("display", null); })
.on("mouseout", function() { tooltip.style("display", "none"); })
.on("mousemove", function(d) {
var xPosition = d3.mouse(this)[0] - 15;
var yPosition = d3.mouse(this)[1] - 25;
tooltip.attr("transform", "translate(" + xPosition + "," + yPosition + ")");
tooltip.select("text").text(d.y);
});
// Prep the tooltip bits, initial display is hidden
var tooltip = svg.append("g")
.attr("class", "tooltip")
.style("display", "none");
tooltip.append("rect")
.attr("width", 30)
.attr("height", 20)
.attr("fill", "white")
.style("opacity", 0.5);
tooltip.append("text")
.attr("x", 15)
.attr("dy", "1.2em")
.style("text-anchor", "middle")
.attr("font-size", "12px")
.attr("font-weight", "bold");
그러나 아직도 빕니다. 로드해야하는 라이브러리가 있습니까? 무슨 일이 일어나고 있는지 잘 모르겠다.
와우! 둘 다 작동하지만 나는 당신에게 동의합니다. div 경로가 훨씬 좋습니다. 감사합니다 제라르도! – user3007270