順序刻度與連續刻度非常相似。在連續規模上,域和範圍之間的映射是連續進行的。唯一的區別是此標度的輸出範圍由其內插器固定,並且該範圍無法更改。
d3.scaleSequential()函數用於創建和返回順序刻度。此比例尺具有指定的範圍和固定範圍。
用法:
d3.scaleSequential([[domain, ]interpolator]);
參數:above-given函數接受上述和以下所述的兩個參數。
- domain:這是最大和最小輸入值範圍。默認域為[0,1]。
- interpolator:這需要一個內插器函數。如果未指定,則默認為身份函數。
返回值:該函數返回一個函數。
範例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>
<h4>d3.scaleSequential() Function</h4>
<script>
var sequential= d3.scaleSequential(
function(t) {
return d3.rgb(t * 400, 1.5, 0.8);
}
)
document.write("<p>sequential(0.1):",
sequential(0.1) + "</p>");
document.write("<p>sequential(0.2):",
sequential(0.2) + "</p>");
document.write("<p>sequential(0.3):",
sequential(0.3) + "</p>");
document.write("<p>sequential(0.4):",
sequential(0.4) + "</p>");
document.write("<p>sequential(0.5):",
sequential(0.5) + "</p>");
document.write("<p>sequential(0.6):",
sequential(0.6) + "</p>");
</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>
<h4>d3.scaleSequential() Function</h4>
<script>
var sequential= d3.scaleSequential(
function(t) {
return d3.interpolateNumber(t * 400, 0, 10);
}
)
document.write("<p>sequential(0.1)(-1):",
sequential(0.1)(-1) + "</p>");
document.write("<p>sequential(0.1)(1):",
sequential(0.1)(1) + "</p>");
document.write("<p>sequential(0.1)(0):",
sequential(0.1)(0) + "</p>");
document.write("<p>sequential(0.1)(0.5):",
sequential(0.1)(0.5) + "</p>");
</script>
</body>
</html>
輸出:
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP array_udiff_uassoc()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- PHP opendir()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
- PHP stream_get_transports()用法及代碼示例
- PHP Ds\Deque pop()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js scaleSequential() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。