D3.js中的nest.map()函數用於生成嵌套Map。該映射包含一個由鍵函數確定的鍵值對,該鍵值對首先執行。如果沒有聲明或定義任何鍵,則map函數將按原樣返回原始數組。
用法:
nest.map(array)
- 它以集合數組作為輸入。
參數:
返回:
以下是上述函數的一些示例
範例1:
定義鍵時。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<title>Document</title>
</head>
<style>
.originalColor{
height:100px;
width:100px;
}
.darkerColor{
height:100px;
width:100px;
}
</style>
<body>
<!-- Fetching from CDN of D3.js -->
<script type = "text/javascript"
src =
"https://d3js.org/d3.v4.min.js">
</script>
<script>
// Forming the collection
let coll=[
{val:"val10", data:"data11"},
{val:"val20", data:"data22"},
{val:"val30", data:"data33"},
{val:"val40", data:"data44"}
]
let data= d3.nest()
.key(function(d) {
return d.val; })
.map(coll)
// Logging the data
console.log(data);
</script>
</body>
</html>
輸出:
範例2:
未定義鍵時。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<title>Document</title>
</head>
<style>
.originalColor{
height:100px;
width:100px;
}
.darkerColor{
height:100px;
width:100px;
}
</style>
<body>
<!--fetching from CDN of D3.js -->
<script type = "text/javascript"
src = "https://d3js.org/d3.v4.min.js">
</script>
<script>
let collection=[
{val:"val10", data:"data11"},
{val:"val20", data:"data22"},
]
//no keys are defined
let data= d3.nest()
.map(collection)
console.log(data);
</script>
</body>
</html>
輸出:
相關用法
- PHP Ds\Set contains()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- PHP abs()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- PHP Ds\Set first()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- p5.js mag()用法及代碼示例
- PHP ord()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP cos( )用法及代碼示例
- p5.js value()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js nf()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js nest.map() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。