time.ticks()函數用於均勻間隔與刻度域相對應的日期。日期始終在比例尺範圍內。
用法:
time.ticks( count )
參數:該函數接受如上所述和以下描述的單個參數:
- count:它是所需的刻度數。它是一個可選參數。
返回值:此函數不返回任何內容。
以下示例程序旨在說明D3.js中的time.ticks()函數:
範例1:
HTML
<!DOCTYPE html>
<html>
<head>
<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>time.ticks() Function </p>
<script>
var time = d3.scaleTime()
// Set the number of ticks
.ticks(4);
// Display the time for each tick
time.forEach(e => {
document.write("<h3>" + e + "</h3>")
});
</script>
</body>
</html>
輸出:
範例2:隔一個間隔。
HTML
<!DOCTYPE html>
<html>
<head>
<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>time.ticks() Function </p>
<script>
var time = d3.scaleTime()
// Set the domain of the time to scale
.domain([new Date(2000, 0, 10, 0),
new Date(2000, 0, 10, 10)])
// Set the number of ticks to every 2 hours
.ticks(d3.timeHour.every(2))
// Display the time for each tick
time.forEach(e => {
document.write("<h3>" + e + "</h3>")
});
</script>
</body>
</html>
輸出:
相關用法
- PHP Ds\Set add()用法及代碼示例
- PHP each()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP Ds\Set first()用法及代碼示例
- PHP Ds\Set last()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js pan()用法及代碼示例
- p5.js value()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- PHP Ds\Set contains()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- d3.js lch()用法及代碼示例
- d3.js d3.max()用法及代碼示例
- p5.js hue()用法及代碼示例
- p5.js min()用法及代碼示例
- p5.js red()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js time.ticks() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。