Skip to content
Related Articles

Related Articles

Improve Article

D3.js zip() Function

  • Last Updated : 19 Jul, 2020
Geek Week

The zip() function in D3.js is used to form a matrix from an array given as a parameter. It helps to visualize data. D3.js stands for Data-Driven Documents.

Syntax:

d3.zip(arrays…)

Parameters:  This function accepts a single parameter as mentioned above and described below:

  • arrays:  This parameter holds the series of arrays.

Return Value: It returns the array of arrays.

Bellow examples illustrate the zip() function in D3.js:



Example 1:

HTML




<!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>
<body>
  <!--fetching from CDN of D3.js-->
  <script type = "text/javascript" 
          src = "https://d3js.org/d3.v4.min.js">
  </script>
  <script>
    console.log("Making matrix using zip function: ")
    let m=d3.zip(["aa","ab","ac"],
                 ["ac","ad","ah"],["ae","af","ag"]);
    console.log("Matrix returned by zip function is: ",m)
  </script>
</body>
</html>

Output:

Example 2: When nothing is given in the parameter an empty array is returned by the zip function.

HTML




<!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>
<body>
  <!--fetching from CDN of D3.js -->
  <script type = "text/javascript" 
          src = "https://d3js.org/d3.v4.min.js">
  </script>
  <script>
    let m=d3.zip();
    console.log("Type of m is: ",typeof(m))
    console.log("Matrix returned by zip function is: ",m)
  </script>
</body>
</html>

Output:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!




My Personal Notes arrow_drop_up
Recommended Articles
Page :