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


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

這個d3.brush()函數在D3.js中用於新創建2-D畫筆。該筆刷一般是創建SVG元素的。

用法:

d3.brush();

參數:該函數不接受任何參數。

返回值:此函數返回一個新創建的筆刷。

例:在此示例中,我們將使用此方法在SVG元素上創建大小為600×600像素的畫筆。



HTML

<!DOCTYPE html>  
<html>  
      
<head>  
    <title>  
        D3.js | d3.brush() Function  
    </title>  
      
    <script src =  
        "https://d3js.org/d3.v4.min.js">  
    </script>  
</head>  
  
<body>  
    <svg width=600 height=600 id="brush"></svg> 
    <script>  
          
        // Selecting SVG element 
        d3.select("#brush") 
        // Creating a brush using the  
        // d3.brush function 
        .call( d3.brush()              
        // Initialise the brush area:start at  
        // 0,0 and finishes at given width,height 
        .extent( [ [0,0], [600,600] ] )        
      ) 
    </script>  
</body>  
  
</html> 

輸出:畫筆創建成功,您可以使用此畫筆拖動以創建矩形。


參考: https://devdocs.io/d3~5/d3-brush#_brush

相關用法


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