1
d3.js에서 초보자이고 일부 텍스트를 추가하고 rect 내부를 rect로 추가하려고합니다. 나는 텍스트와 RECT의 SVG 내부 mainBox를 추가 할d3 SVG rect에 텍스트 추가
if (!_svg) {
_svg = d3.select("#col1").append("svg")
.attr("height", _height - 2)
.attr("width", _width - 2);
}
_svg.append("text").attr({
id: "leftDomainName",
x: d3.select("svg").attr("width")/14,
y: d3.select("svg").attr("height")/2,
class: "vertical-text"
}).text("Business Development");
var g = _svg.append("g").attr("transform", function (d, i) {
return "translate(0,0)";
}).attr("clip-path", "url(#body-clip)");
var mainBox = g.append("rect").attr({
id: "mainBox",
x: d3.select("svg").attr("width")/8,
y: 3,
width: _width - 60,
height: _height/3,
fill: "#D7FFEC"
});
mainBox.append("text").text("sample!!!");
mainBox.append("rect").attr({
x: 50,
y: 50,
width: _width - 60,
height: _height/3,
fill: "red"
});
:
여기 내 코드입니다. 크롬 develper 도구에서 나는 자신이 추가되었습니다 볼 수 있지만
내 잘못 무엇 페이지
에 존재하지 않습니다? 내가 mainBox에 g을 추가하고 해당 g 내 요소를 추가은 감사하지만
var innerG = mainBox.append("g");
innerG.append("text").text("sample!!!");
innerG.append("rect").attr({
x: 50,
y: 50,
width: _width - 60,
height: _height/3,
fill: "red"
});
이
의 당신이 mainBox의 내부 의미 : 당신이 원하는 것을 달성하기 위해, 모두
text
및rect
을 포함하는g
요소를 추가? 나는 그것을했지만 작동하지 않았다. 내 새로운 코드를 qustion 섹션에 추가합니다. – farhad아,이 모든 것을 다른 'rect'요소에 추가 한 것처럼 보입니다. 같은 이유로 작동하지 않을 것입니다. 요소를 그룹화하려면'g' 요소를 사용하십시오. –
귀하의 의견을 후, 그들을 그룹화했지만 작동하지 않았다. 질문 섹션에서 굵게 기울임 꼴 라인을 참조하십시오 – farhad