d3.js中的time.domain()函數用於設置時間範圍的域。如果未指定域,則默認域為[2000-01-01、2000-01-02]。
用法:
time.domain([domain]);
參數:該函數接受上麵給出的和下麵描述的一個參數。
- domain:這需要一個數字數組。默認值為[2000-01-01、2000-01-02]。
返回值:此函數不返回任何內容。
範例1:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" path1tent="width=device-width,
initial-scale=1.0" />
<title>Geeks for geeks</title>
<script src="https://d3js.org/d3.v4.min.js">
</script>
<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>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<p>D3.js time.domain() Function </p>
<script>
var time = d3.scaleTime()
// Setting domain for the scale
.domain([2011 - 01 - 01, 2015 - 05 - 02]);
document.write("<h3>time(1):" + time(1) + "</h3>");
document.write("<h3>time(2):" + time(2) + "</h3>");
document.write("<h3>time(3):" + time(3) + "</h3>");
document.write("<h3>time(4):" + time(4) + "</h3>");
</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>
<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>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<p>D3.js time.domain() Function </p>
<script>
// Setting domain for the scale
var time = d3.scaleTime()
.domain(["2011-01-01", "2015-05-02"]);
document.write("<h3>time(10):"
+ time(10) + "</h3>");
</script>
</body>
</html>
輸出:
範例3:
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>
<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>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<p>D3.js time.domain() Function </p>
<script>
// Setting domain for the scale
var time = d3.scaleTime()
.domain([1, 100])
// default range is used.
document.write("<h3>time(1):" + time(1) + "</h3>");
document.write("<h3>time(2):" + time(2) + "</h3>");
document.write("<h3>time(3):" + time(3) + "</h3>");
document.write("<h3>time(4):" + time(4) + "</h3>");
</script>
</body>
</html>
輸出:
相關用法
- p5.js box()用法及代碼示例
- p5.js arc()用法及代碼示例
- d3.js d3.min()用法及代碼示例
- CSS hsl()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- d3.js arc()用法及代碼示例
- PHP chr()用法及代碼示例
- p5.js nfc()用法及代碼示例
- p5.js nfs()用法及代碼示例
- p5.js nfp()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js nf()用法及代碼示例
- d3.js d3.rgb()用法及代碼示例
- CSS url()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- PHP pi( )用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js time.domain() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。