使用D3在单个图像上附加多个多边形
我有这些多边形来自变量并存储在poly中,因此在网页上显示多边形,但我希望所有多边形都显示在单个图像上,因此我应该在此处使用D3在此处编写代码以显示所有的代码多边形仅在该特定图像上。
请帮助,在过去的几天里,我一直在尝试这些方法,但找不到适当的解决方案。
...
var vis = d3.select("body").append("svg")
.attr("width", 1000)
.attr("height", 667),
poly = [{"x":x1, "y":y1},
{"x":x2,"y":y2},
{"x":x3,"y":y3},
{"x":x4,"y":y4}];
vis.selectAll("polygon")
.data([poly])
.enter().append("polygon")
.attr("points",function(d) {
return d.map(function(d) { return [d.x,d.y].join(","); }).join(" ");})
.attr("stroke","red")
.attr("fill","none"); }
... ...
I have these polygons coming from variables and being stored in poly, so polygons are being displayed all over the webpage but I want all the polygons to be displayed on a single image, so how should I write the code here using D3 to display all the polygons on that specific image only.
Please help, I have been trying these for the last few days but couldn't find a proper solution.
...
var vis = d3.select("body").append("svg")
.attr("width", 1000)
.attr("height", 667),
poly = [{"x":x1, "y":y1},
{"x":x2,"y":y2},
{"x":x3,"y":y3},
{"x":x4,"y":y4}];
vis.selectAll("polygon")
.data([poly])
.enter().append("polygon")
.attr("points",function(d) {
return d.map(function(d) { return [d.x,d.y].join(","); }).join(" ");})
.attr("stroke","red")
.attr("fill","none"); }
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用SVG的ViewBox属性。查看框应匹配图像的边缘,并应扩展到图像的高度和宽度。设置了视图框后,将CSS更改以覆盖SVG超过图像。
我已经更改了下面的代码以获取示例图像
Use the viewBox property of the svg. Viewbox should match the margins of the image and it should expand to the height and width of the image. Once viewBox is set, change the css for overlay of the svg over image.
I have changed the code below for a sample image
您到底在网页上显示多边形并希望它们显示在特定图像上的多边形是什么意思?
What exactly do you mean by polygons being displayed all over the webpage and wanting them displayed on a specific image?