D3.js主要用於製作圖形和可視化HTML SVG元素上的數據。 D3.js具有許多函數,其中之一是arc()函數。 Path.arc()函數用於製作圓弧和圓形以及其他形狀。 D3代表數據驅動文檔,主要用於數據可視化。
用法:
path.arc(x, y, radius, startAngle, endAngle[anticlockwise])
參數:此函數接受上述和以下所述的五個參數:
- x:此參數保存SVG中圓弧的x-position。
- y:此參數保存SVG中圓弧的y-position。
- radius:此參數保存要形成圓弧的半徑。
- startAngle:此參數保存圓弧的起始角度。
- endAngle [逆時針]:此參數保存要形成圓弧的角度,如果逆時針為true,則沿逆時針方向繪製圓弧。
注意:如果當前點不等於圓弧的起點,則從當前點到圓弧的起點繪製一條直線。
下麵的示例說明了D3.js | D3.js中的Path.arc()函數:
範例1:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
path1tent="width=device-width,
initial-scale=1.0">
<title>D3.js| Path.arc() Function</title>
</head>
<style>
body {
text-align:center;
}
h1 {
color:green;
}
svg{
background-color:green;
}
.path1{
fill:aliceblue;
}
</style>
<body>
<h1>GeeksforGeeks</h1>
<b>D3.js | Path.arc() Function</b>
<div>
<svg width="300" height="300">
<text x="50" y="50" font-family="Verdana"
font-size="22" fill="white">
SVG Element
</text>
<path class="path1">
</svg>
</div>
<script src =
"https://d3js.org/d3.v4.min.js">
</script>
<script>
// Creating path object
var path1= d3.path();
// Creating arc of radius 100
path1.arc(150,150,100,0,3.14)
d3.select(".path1").attr("d",path1);
</script>
</body>
</html>
輸出:
範例2:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
path1tent="width=device-width,
initial-scale=1.0">
<title>D3.js| Path.arc() Function</title>
</head>
<style>
body {
text-align:center;
}
h1 {
color:green;
}
svg{
background-color:green;
}
.path1{
fill:aliceblue;
}
</style>
<body>
<h1>GeeksforGeeks</h1>
<b>D3.js | Path.arc() Function</b>
<div>
<svg width="300" height="300">
<text x="40" y="40" font-family="Verdana"
font-size="22" fill="white">
SVG Element
</text>
<path class="path1">
</svg>
</div>
<script src =
"https://d3js.org/d3.v4.min.js">
</script>
<script>
// Creating path object
var path1= d3.path();
// Creating arc of radius 100
path1.arc(150,150,100,0,2*3.14)
d3.select(".path1").attr("d",path1);
</script>
</body>
</html>
輸出:
相關用法
- d3.js d3.map.has()用法及代碼示例
- d3.js d3.map.get()用法及代碼示例
- d3.js d3.set.add()用法及代碼示例
- p5.js nfc()用法及代碼示例
- p5.js nf()用法及代碼示例
- d3.js d3.min()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- p5.js box()用法及代碼示例
- p5.js value()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js nfp()用法及代碼示例
- p5.js arc()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- p5.js nfs()用法及代碼示例
- p5.js mag()用法及代碼示例
- d3.js d3.max()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js | Path.arc() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。