D3.js中的ribbon.radius()函數用於將半徑訪問器設置為指定的函數,並返回此Ribbon生成器。
用法:
ribbon.radius([radius]);
參數:該函數接受如上所述和以下描述的單個參數
- radius:此參數是設置半徑訪問器的函數。
返回值:此函數返回色帶生成器。
以下示例程序旨在說明函數區.D3.js中的radius()函數
範例1:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.js"></script>
</head>
<body>
<center>
<h1 style="color:green;">GeeksForGeeks</h1>
<h3>D3.js | ribbon.radius() Function</h3>
<div id="GFG"></div>
<script>
// Create the svg area
var svg = d3.select("#GFG")
.append("svg")
.attr("width", 340)
.attr("height", 340)
.append("g")
.attr("transform", "translate(170, 170)")
// Create input data
var data = [[148, 60, 71, 34, 5, 1],
[ 10, 80, 80, 12, 34, 53],
[175, 16, 68, 0, 0, 3],
[13, 9, 69, 76, 35, 4],
[51, 60, 71, 34, 5, 1]];
// Give this matrix to d3.chord()
var chords = d3.chord()(data)
var ribboon = d3.ribbon()
// Use of ribbon.radius() function
.radius(170);
svg.datum(chords)
.append("g")
.selectAll("path")
.data(function (d) { return d; })
.enter()
.append("path")
.attr("d", ribboon)
.style("fill", "#ffb357")
.style("stroke", "black");
</script>
</center>
</body>
</html>
輸出:
範例2:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src= "https://d3js.org/d3-color.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-interpolate.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-scale-chromatic.v1.min.js">
</script>
</head>
<body>
<center>
<h1 style="color:green;">GeeksForGeeks</h1>
<h3>D3.js | ribbon.radius() Function</h3>
<div id="GFG"></div>
<script>
// Create the svg area
var svg = d3.select("#GFG")
.append("svg")
.attr("width", 320)
.attr("height", 320)
.append("g")
.attr("transform", "translate(160, 160)")
// Create input data
var data = [[0, 58, 71, 89, 16, 28, 68, 0],
[0, 19, 51, 0, 20, 60, 61, 71],
[80, 10, 16, 145, 0, 80, 45, 0],
[0, 10, 13, 9, 90, 94, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]];
// 4 groups, so create a vector of 4 colors
var colors = [d3.schemeSet1[7], d3.schemeSet1[6],
d3.schemeSet1[5], d3.schemeSet1[4],
d3.schemeSet1[3], d3.schemeSet1[2],
d3.schemeSet1[1], d3.schemeSet1[0]];
// Give this matrix to d3.chord()
var chords = d3.chord()(data)
var rib = d3.ribbon()
// Use of ribbon.radius() function
.radius(150);
svg.datum(chords)
.append("g")
.selectAll("path")
.data(function (d) { return d; })
.enter()
.append("path")
.attr("d", rib)
.style("fill", function (d) {
return (colors[d.source.index])
})
.style("stroke", "black");
</script>
</center>
</body>
</html>
輸出:
相關用法
- d3.js now()用法及代碼示例
- p5.js mag()用法及代碼示例
- PHP next()用法及代碼示例
- d3.js zip()用法及代碼示例
- d3.js lch()用法及代碼示例
- d3.js tsv()用法及代碼示例
- p5.js pan()用法及代碼示例
- CSS var()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- PHP chr()用法及代碼示例
- PHP ord()用法及代碼示例
- CSS hsl()用法及代碼示例
- p5.js min()用法及代碼示例
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 D3.js ribbon.radius() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。