d3.js - D3 lineRadial 不显示,而其他元素显示
问题描述
我将以下“时钟指针”实现为 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");
解决方案
lineRadial
不是一个有效的 svg 组件,你必须说line
(在你的第二个代码片段中,也不angle
是一个有效的line
属性,你应该说:
.attr("transform", "rotate(90)")
我建议阅读文档进行旋转,因为它需要 3 个参数。这是一个解释: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://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform
最后,请注意角度必须以度为单位传递。
推荐阅读
- c++ - Visual Studio 2019 C++ 和 std::filesystem 更改为 ISO C++17 标准或添加 _HAS_CXX17 1 不起作用
- hibernate - org.hibernate.QueryParameterException:超出声明序数参数数量的位置
- python-3.x - python的grep、awk和sed替代品?
- javascript - 为什么 Messenger 中的消息没有按顺序发送?
- sql - 查询列在哪里显示数据库中每个表中的第一个条目?
- javascript - Firebase 实时数据库后端异步功能不更新用户
- python - 我正在尝试使用 api.lookup_user 访问一些 twitter 用户 ID,但是当我运行它时,我得到 tweeperror
- html - 了解定位元素的绝对行为
- java - 无法在 java 应用程序中包含字体文件夹
- html - Safari 输入 type="number" 和模式不会阻止字母输入