Open In App

D3.js | Path.rect() Function

Last Updated : 16 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

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




         // 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);


Output:

Example 2:

Javascript




         // 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);


Output:



Next Article

Similar Reads