D3.js rollup() method Last Updated : 06 Apr, 2023 Comments Improve Suggest changes Like Article Like Report With the help of d3.rollup() method, we can get the reduced map from an iterable data structure having keys and values. Syntax: d3.rollup(iterable, reduce, ...keys) Return value: It will return the reduced map from iterables. Note: To execute the below examples you have to install the d3 library by using the command prompt for the following command. npm install d3 Example 1: In this example, we can see that by using the d3.rollup() method, we are able to get the reduced map from an iterable data structure having keys and values. JavaScript // Defining d3 contrib variable const 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: "ABC", amount: "34.05", date: "01/04/2016" } ] let gfg = d3.rollup(data, g => g.length, d => d.amount); console.log(gfg); Output: Map { '34.0' => 1, '120.11' => 1, '12.01' => 1, '34.05' => 1 } Example 2: JavaScript // Defining d3 contrib variable const 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: "DEF", amount: "34.05", date: "03/04/2020" } ] const gfg = d3.rollup(data, g => g.length, d => d.name, d => d.date); console.log(gfg); Output: Map { 'ABC' => Map { '11/12/2019' => 1 }, 'DEF' => Map { '11/02/2020' => 1, '03/04/2020' => 1 }, 'MNO' => Map { '01/04/2020' => 1 } } Comment More infoAdvertise with us Next Article D3.js rollup() method J jitender_1998 Follow Improve Article Tags : JavaScript Web Technologies Node.js D3.js Similar Reads D3.js rollups() method With the help of d3.rollups() method, we can get the reduced nested array instead of map from iterable data structure having key and values. Syntax: d3.rollups(iterable, reduce, ...keys) Return value: It will return the reduced nested array instead of map. Note: To execute the below examples you hav 2 min read D3.js stack.value() Method The stack.value() method takes a function that returns the value associated with a key. Syntax: stack.value([value_func]) Parameters: This function accepts a single parameter as mentioned above and described below: value_func: This is a function returning the value associated with the key. Return Va 1 min read D3.js fsum() Method With the help of d3.fsum() method, we can get the full precision sum of a floating point array values by using this method and return sum of all the values. Syntax: d3.fsum([values]) Parameter: This function has the following parameter as mentioned above and described below: values: It is an array o 2 min read Underscore.js _.add() Method The _.add() method returns the sum of all the given arguments. Syntax: _.add(val1, val2,..., valn); Parameters: This method returns n values to operate on them. Return Value: This method returns the sum of all the given arguments. Note: This will not work in normal JavaScript because it requires the 1 min read D3.js Adder() Method With the help of d3.Adder() method, we can get the adder to compute the full precision sum of floating point values and set 0 as a default value by using this method. Syntax: const adder = new d3.Adder() Parameter: This function has no parameters. Return Value: It returns the adder to compute the fu 2 min read Like