當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


d3.js d3.timeMinutes()用法及代碼示例


D3.js中的d3.timeMinutes()函數用於返回所有時間,以分鍾為單位,日期在給定的開始和結束時間範圍內。

用法:

d3.timeMinutes( start, end, step );

參數:該函數接受以下三個參數:


  • Start:此參數保存給定的開始時間。
  • end:此參數保存給定的結束時間。
  • step:它是可選參數,其中包含用於跳過分鍾的值。

返回值:此函數返回給定範圍內所有可能的分鍾。

以下程序說明了D3.js中的d3.timeMinutes()函數:

示例1:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        D3.js | d3.timeMinutes() Function 
    </title> 
      
    <script src =  
        "https://d3js.org/d3.v4.min.js"> 
    </script> 
</head> 
  
<body>     
    <script> 
          
        // Initialising start and end time 
        var start = new Date(2015, 07, 01, 4, 10); 
        var end = new Date(2015, 07, 01, 4, 15); 
          
        // Calling the timeMinutes() function 
        // without step value 
        var a = d3.timeMinutes(start, end); 
          
        // Getting the minute values 
        console.log(a); 
    </script> 
</body> 
  
</html>    

輸出:

["2015-07-31T22:40:00.000Z", "2015-07-31T22:41:00.000Z", "2015-07-31T22:42:00.000Z", 
"2015-07-31T22:43:00.000Z", "2015-07-31T22:44:00.000Z"]

示例2:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        D3.js | d3.timeMinutes() Function 
    </title> 
      
    <script src =  
        "https://d3js.org/d3.v4.min.js"> 
    </script> 
</head> 
  
<body>     
    <script> 
          
        // Initialising start and end time 
        var start = new Date(2015, 07, 01, 4, 10); 
        var end = new Date(2015, 07, 01, 4, 15); 
            
        // Calling the timeMinutes() function 
        // with step value 
        var a = d3.timeMinutes(start, end, 2); 
            
        // Getting the minute values 
        console.log(a); 
    </script> 
</body> 
  
</html>    

輸出:

["2015-07-31T22:40:00.000Z", "2015-07-31T22:42:00.000Z", "2015-07-31T22:44:00.000Z"]

參考: https://devdocs.io/d3~5/d3-time#timeMinutes



相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 D3.js | d3.timeMinutes() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。