D3.js cumsum() Method
With the help of d3.cumsum() method, we can get the cumulative sum of all the values of an array, that is the value at ith index is the cumulative sum of values from index 0 to index i by using this method.
d3.cumsum( iterable )
Parameter: This function has the following parameter as mentioned above and described below:
- iterable: Insert any kind of iterable object.
Return Value: It returns the cumulative sum of all the values.
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.cumsum() method, we are able to compute the cumulative sum of all the values from index 0 to ith at index ith by using this method.
Float64Array [ 5, 9, 12, 14, 15 ]
Example 2: Filename: index.js
Float64Array(5) [ 0, 1, 3, 6, 10 ]
Note: The above program will compile and run by using the following command: