0
如何在矩形内添加多边形?,下面是我有的代码,但它没有显示矩形内的多边形。你可以帮我吗。d3.js在矩形内添加多边形
var svgContainer = d3.select("body").append("svg")
var rectangle = svgContainer.append("rect")
.style("stroke", "black")
.style("fill", "none")
.attr("x", 50)
.attr("y", 50)
.attr("width", 100)
.attr("height", 100);
var cir = rectangle.append("polygon") // attach a polygon
.style("stroke", "black") // colour the line
.style("fill", "none") // remove any fill colour
.attr("points", "30,50,100,150,100,150"); // x,y points
感谢细节 - 西里尔。有没有办法我可以将三角形恰好放在矩形的中心。 – gorants
@gorants你可以通过计算中心并提供数组中的点来确定任何三角形的中心点击这里查看我的演示http://jsfiddle.net/pgerw8va/2/ 现在你将不得不编写一个算法来计算一个中心点数字。 – Cyril
谢谢Cyril ..赞赏你的帮助 – gorants