D3.js庫中的band.range()函數用於將刻度範圍設置為指定的兩元素數字數組。範圍的默認值為[0,1]。
用法:
band.range([range]);
參數:該函數接受上麵給定和下麵描述的單個參數。
- range:此參數接受一個包含兩個元素的數字數組。
注意:如果範圍中的元素不是數字,則將其強製為數字。
返回值:此函數不返回任何內容。
下麵給出的是上麵給出的函數的一些例子。
範例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>
<script>
// Create the band scale with specified
// domain and range.
var band = d3.scaleBand()
.domain([0, 1])
.range([0, 1]);
console.log("When range is [0, 1]");
console.log("band(0):", band(0));
console.log("band(1):", band(1));
var band = d3.scaleBand()
.domain([0, 1])
.range([10, 20]);
console.log("When range is [10, 20]");
console.log("band(0):", band(0));
console.log("band(1):", band(1));
</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>
<script>
// Create the band scale with specified
// domain and range.
var band = d3.scaleBand()
.domain([0, 1])
// These chars are coerced to numbers
.range(["1", "2"]);
console.log("When range is [\"1\", \"2\"]");
console.log("band(0):", band(0));
console.log("band(1):", band(1));
var band = d3.scaleBand()
.domain([0, 1])
// These chars are coerced to numbers
.range(["100", "200"]);
console.log("When range is [\"100\", \"200\"]");
console.log("band(0):", band(0));
console.log("band(1):", band(1));
</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 band.range() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。