D3.js | Path.rect() Function - GeeksforGeeks

16 Jun, 2020
D3.js is a library in Javascript, this library is mostly used for making of graph and visualizing data on the HTML SVG elements. D3 stands for Data Driven Documents and mostly used for data visualization. The Path.rect() is used to make a rectangle in a svg element.
Syntax:
Path.rect(x, y, w, h);
Parameters: This function accepts four parameter as mentioned above and described below:
X: It is the x-position of the rectangle.
Y: It is the y-position of the rectangle.
W: It is the width of the rectangle.
H: It is the height of the rectangle
Below example illustrate function in D3.js
Example 1:
Javascript
<!DOCTYPE html><html lang="en">   <head>      <meta charset="UTF-8">      <meta name="viewport"             path1tent="width=device-width,                        initial-scale=1.0">      <title>D3.js | Path.rect() function</title>   </head>   <style>      h1 {          color: green;      }      body {          text-align: center;      }      svg{      background-color: green;      }      .path1{      fill: aliceblue;      }   </style>   <body>      <div>         <h1>GeeksforGeeks</h1>         <b>D3.js | Path.rect() function</b>         <br>         <svg width="400" height="300">            <text x="50" y="50" font-family="Verdana"                   fill="white">                SVG Element            </text>            <path class="path1">         </svg>      </div>      <script src ="https://d3js.org/d3.v4.min.js">      </script>      <script>         // Creating path object         var path1= d3.path();                    // Creating rectangle at x:50 and y:100         // and height:200, width:300         path1.rect(50,70,300,200);          d3.select(".path1").attr("d",path1);      </script>   </body></html>
Output:
Example 2:
Javascript
<!DOCTYPE html><html lang="en">   <head>      <meta charset="UTF-8">      <meta name="viewport"             path1tent="width=device-width,                        initial-scale=1.0">      <title>D3.js | Path.rect() function</title>   </head>   <style>      h1 {          color: green;      }      body {          text-align: center;      }      svg{      background-color: green;      }      .path1{      fill: aliceblue;      }   </style>   <body>      <div>         <h1>GeeksforGeeks</h1>         <b>D3.js | Path.rect() function</b>         <br>         <svg width="400" height="300">            <text x="50" y="50" font-family="Verdana"                   fill="white">                SVG Element            </text>            <path class="path1">         </svg>      </div>      <script src ="https://d3js.org/d3.v4.min.js">      </script>      <script>         // Creating path object         var path1= d3.path();                    // Creating rectangle at x:50 and y:100         // and height:200, width:300         path1.rect(100, 70, 200, 200);          d3.select(".path1").attr("d",path1);      </script>   </body></html>
Output:
D3.js
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to append HTML code to a div using JavaScript ?
How to Open URL in New Tab using JavaScript ?
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?