D3.js group.get() Method

With the help of d3.group.get() method, we can get the values from the resulting map obtained by grouping an iterable data structure.

Syntax:

d3.group.get( value )

Return value: It returns the values from the map.

Note: To execute the below examples you have to install the d3 library by using this command prompt we have to execute the following command.

npm install d3

Example 1: In this example, we can see that by using d3.group.get() method, we are able to get the values from the resulting map obtained from the group.



Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining d3 contrib variable  
var d3 = require('d3');
  
data = [
  {name: "ABC", amount: "34.0",   date: "11/12/2015"},
  {name: "DEF", amount: "120.11", date: "11/12/2015"},
  {name: "MNO", amount: "12.01",  date: "01/04/2016"},
  {name: "XYZ", amount: "34.05",  date: "01/04/2016"}
]
  
var grouped_data = d3.group(data, d => d.name)
  
console.log(grouped_data.get("ABC"))

chevron_right


Output:

[ { name: 'ABC', amount: '34.0', date: '11/12/2015' } ]

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining d3 contrib variable  
var d3 = require('d3');
  
data = [
  {name: "ABC", amount: "34.0",   date: "11/12/2019"},
  {name: "DEF", amount: "120.11", date: "11/02/2020"},
  {name: "MNO", amount: "12.01",  date: "01/04/2020"},
  {name: "XYZ", amount: "34.05",  date: "03/04/2020"}
]
  
var grouped_data = d3.group(data, d => d.name, d => d.date)
  
console.log(grouped_data.get("XYZ"))

chevron_right


Output:

Map {
  '03/04/2020' => [ 
    { name: 'XYZ', amount: '34.05', date: '03/04/2020' } ]
}

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.