D3.js area() Method

The d3.area() method in D3.js is used to return an area generator with default settings that can be further used to create areas.
Syntax:
d3.area()
Parameters: This method does not accept parameters.
Return Value: This method returns no value.
Below examples illustrate the d3.area() method in D3.js:
Example 1:
HTML
| <!DOCTYPE html> <html>  Â<head>     </script> </head>  Â<body>     <h1style="text-align: center;              color: green;">         zambiatek     </h1>  Â    <center>         <svgid="gfg"width="200"height="200">         </svg>     </center>      Â    <script>         var data = [             { x: 0, y: 10 },             { x: 10, y: 30 },             { x: 20, y: 150 },             { x: 50, y: 10 },             { x: 60, y: 150 },             { x: 70, y: 50 },             { x: 80, y: 190 }];  Â        data.sort((a, b) => a.y - b.y);  Â        var xScale = d3.scaleLinear()             .domain([0, 8])             .range([25, 200]);         var yScale = d3.scaleLinear()             .domain([0, 20])             .range([200, 25]);  Â        // Using area() function to         // generate area         var Gen = d3.area()             .x((p) => p.x)             .y0((p) => 0)             .y1((p) => p.y);  Â        d3.select("#gfg")             .append("path")             .attr("d", Gen(data))             .attr("fill", "green")             .attr("stroke", "black");     </script> </body>  Â</html>  | 
Output:
Example 2:
HTML
| <!DOCTYPE html> <html>  Â<head>     </script> </head>  Â<body>     <h1style="text-align: center;               color: green;">         zambiatek     </h1>  Â    <center>         <svgid="gfg"width="250"height="200">         </svg>     </center>      Â    <script>         var points = [             { xpoint: 25, ypoint: 150 },             { xpoint: 75, ypoint: 50 },             { xpoint: 100, ypoint: 150 },             { xpoint: 100, ypoint: 50 },             { xpoint: 200, ypoint: 150 }];  Â        // Using area() function to generate area         var Gen = d3.area()             .x((p) => p.xpoint)             .y0((p) => 0)             .y1((p) => p.ypoint);  Â        d3.select("#gfg")             .append("path")             .attr("d", Gen(points))             .attr("fill", "green")             .attr("stroke", "black");  Â    </script> </body>  Â</html>  | 
Output:
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					



