threshold.range()函數用於設置閾值刻度的範圍。範圍數組中的值的數量總是比域數組大一,如果不這樣,則刻度的行為可能不確定。
用法:
threshold.range([range]);
參數:該函數接受上麵給定和下麵描述的單個參數。
- range:此參數接受離散值數組。如果域中存在數量為“n”的值,則範圍必須具有數量為“n+1”的值。
返回值:此函數不返回任何值。
範例1:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" path1tent=
"width=device-width,initial-scale=1.0" />
<script src="https://d3js.org/d3.v4.min.js">
</script>
</head>
<body>
<h2 style="color:green;">GeeksforGeeks</h2>
<p>threshold.range() Function </p>
<script>
var threshold = d3.scaleThreshold()
// Setting domain for the scale.
.domain([10, 20, 30, 40])
// Setting the range for the scale.
// Number of elements is one more
// then domain array size.
.range(["red", "blue",
"green", "yellow", "white"]);
document.write("<h4>"
+ threshold(10) + "</h4>");
document.write("<h4>"
+ threshold(20) + "</h4>");
</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" />
<script src="https://d3js.org/d3.v4.min.js">
</script>
</head>
<body>
<h2 style="color:green;">GeeksforGeeks</h2>
<p>threshold.range() Function </p>
<script>
var threshold = d3.scaleThreshold()
// Setting domain for the scale.
.domain([10, 20, 30, 40])
// Setting the range for the scale.
// Number of elements is one more
// then domain array size.
.range([0.01, 0.02, 0.03, 0.04, 0.05]);
document.write("<h4>"
+ threshold(20) + "</h4>"); // 0.03
document.write("<h4>"
+ threshold(40) + "</h4>"); // 0.05
// This value is outside the domain
document.write("<h4>"
+ threshold(500) + "</h4>"); // 0.05
</script>
</body>
</html>
輸出:
相關用法
- PHP Ds\Set xor()用法及代碼示例
- p5.js value()用法及代碼示例
- d3.js d3.sum()用法及代碼示例
- p5.js pan()用法及代碼示例
- PHP max( )用法及代碼示例
- d3.js d3.mean()用法及代碼示例
- PHP ord()用法及代碼示例
- d3.js d3.min()用法及代碼示例
- p5.js nfs()用法及代碼示例
- p5.js nf()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js nfc()用法及代碼示例
- p5.js nfp()用法及代碼示例
- d3.js now()用法及代碼示例
- PHP Ds\Set last()用法及代碼示例
- PHP Ds\Set add()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js threshold.range() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。