javascript - 如何填充圆圈中3点之间的空间?
问题描述
我必须在圆的边界和圆的中间点上点。我想将这三个点之间的空间(饼图)涂成红色(包括“弧线”)。它不必在 svg 中。
const AzimuthChart = (props) => {
const x1 = 428.9397
const y1 = 159.2263
const x2 = 371.3345
const y2 = 159.0330
return (
<div className="App">
<svg preserveAspectRatio="xMidYMin" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 400">
<g fill="#61DAFB">
<circle cx="400" cy="200" r="50"/>
<circle cx="400" cy="200" r="1" fill='red'/>
<circle cx={x2} cy={y2} r='1' fill='red'/>
<circle cx={x1} cy={y1} r='1' fill='red'/>
</g>
</svg>
</div>
)
}
导出默认方位图
这就是它现在的样子:
这就是我想要的样子:
我试过添加一个弧:
<path d='M 449.89 203.252 A 1 1 0 0 0 350 202.8' fill='red'/>
但这只是创造了半个圆圈。有人对如何解决这些问题有想法吗
解决方案
您只需将这些点插入椭圆弧命令。请注意,由于您需要“大”弧而不是“小”弧,因此您需要将大弧标志设置为 1。
const x1 = 428.9397
const y1 = 159.2263
const x2 = 371.3345
const y2 = 159.0330
let path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
path.setAttribute("d", `M ${x2} ${y2} A 50 50 0 1 0 ${x1} ${y1} L 400 200 Z`)
path.setAttribute("fill", "red");
document.getElementsByTagName('svg')[0].appendChild(path);
<svg viewBox="0 0 800 400">
<circle cx="400" cy="200" r="50" fill="#61DAFB"/>
</svg>
推荐阅读
- java - 仅使用增量、减量、循环和 =0 来创建 pow(x1, x2) 函数
- css - 我正在使用 Prestashop,我需要找到某些 css 文件并进行更改,你能帮我吗?
- http - 如何将非虚拟主机从 http 重定向到 https
- r - lubridate::interval 对象中身份的评估错误
- java - 此代码是否线程安全,使用 Java 8 Lambda - stream.forEach
- mongodb - MongoDB 在匹配、分组和排序后获得完整的文档
- sql-server - SQL Server:AFTER INSERT 触发器无法正常工作,即使确保在 SSIS 包中设置了 FIRE_TRIGGERS
- rust - 期权类型和提前回报。is_none() 时返回错误
- sql - 未使用 Postgres 索引
- android - Android中的SQLite在datelike字符串的开头和结尾添加引号