D3.js中的transpose()函數用於返回2D數組的轉置。此函數有助於可視化數據並製作圖形和圖表。
用法:
d3.transpose(Matrix);
參數:該函數接受如上所述和以下描述的單個參數:
- Matrix:此參數將矩陣保存為2d數組
返回值:它返回一個數組或矩陣。
下麵給出了轉置函數的一些示例。
範例1:無需使用zip函數即可形成矩陣。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>D3.js transpose() Function</title>
</head>
<body>
<!--Fetching from CDN of D3.js-->
<script type = "text/javascript"
src = "https://d3js.org/d3.v4.min.js">
</script>
<script>
console.log(d3.transpose([[1,2,3],[4,5,6]]))
</script>
</body>
</html>
輸出:
範例2:使用zip函數形成矩陣。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>D3 transpose() Function</title>
</head>
<body>
<!--Fetching from CDN of D3.js-->
<script type = "text/javascript"
src = "https://d3js.org/d3.v4.min.js">
</script>
<script>
console.log("Making matrix using zip function:")
let m=d3.zip(["a","b","s"],["c","d","h"],["e","f","g"]);
console.log("Original Matrix:",m)
console.log("Transpose matrix:",d3.transpose(m))
</script>
</body>
</html>
輸出:
支持的瀏覽器:
- 穀歌瀏覽器
- IE瀏覽器
- 火狐瀏覽器
- Safari
- Opera
相關用法
- p5.js nfs()用法及代碼示例
- p5.js box()用法及代碼示例
- p5.js nfc()用法及代碼示例
- PHP Ds\Set add()用法及代碼示例
- p5.js nfp()用法及代碼示例
- d3.js d3.set.add()用法及代碼示例
- PHP next()用法及代碼示例
- p5.js nf()用法及代碼示例
- PHP max( )用法及代碼示例
- PHP min( )用法及代碼示例
- d3.js d3.sum()用法及代碼示例
- CSS url()用法及代碼示例
- d3.js d3.mean()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- PHP end()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js transpose() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。