我将下面的“时钟之手”实现为lineRadial。但是,它没有显示出来。为什么不行?
const line = d3.select("svg")
.append("lineRadial")
.attr("angle", -Math.PI / 2)
.attr("radius", 60)
.attr("stroke", "red")
.attr("stroke-width", "2")
.attr("transform", "translate(60,60)");
我不明白,我在svg中还有其他可以正常工作的元素。即使是另一行代码(如下所示)也可以找到。有什么解释吗?有什么不同吗?
const line = d3.select("svg")
.append("line")
.attr("x1", 0).attr("y1", 0).attr("x2", 0).attr("y2", -60)
.attr("stroke", "red")
.attr("stroke-width", "2");
发布于 2020-03-29 16:16:08
lineRadial
不是一个有效的svg组件,您必须说line
(就像在您的第二个代码片段中一样,angle
也不是一个有效的line
属性,您应该这样说:
.attr("transform", "rotate(90)")
我建议阅读旋转文档,因为它需要3个参数。这里有一个解释:来自https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform的The rotate(<a> [<x> <y>]) transform function specifies a rotation by a degrees about a given point. If optional parameters x and y are not supplied, the rotation is about the origin of the current user coordinate system. If optional parameters x and y are supplied, the rotate is about the point (x, y).
最后,请注意角度必须以度为单位传递。
https://stackoverflow.com/questions/60915921
复制