D3.js group.get() Method
Last Updated :
23 Sep, 2020
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
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" ))
|
Output:
[ { name: 'ABC', amount: '34.0', date: '11/12/2015' } ]
Example 2:
Javascript
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" ))
|
Output:
Map {
'03/04/2020' => [
{ name: 'XYZ', amount: '34.05', date: '03/04/2020' } ]
}
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...