The d3.area.x() method is used to set the x accessor to the argument passed to it which may be either a number or a function that returns a number.
Syntax:
d3.area.x(x_point)
Parameters: This function accepts a single parameter as mentioned above and described below.
- x_point: This parameter is a number representing a point or a function that returns a number.
Return Value: This method returns no value.
Example 1:
<!DOCTYPE html> < html > < head >     < meta charset = "utf-8" >       < script src =     </ script > </ head >   < body >     < h1 style = "text-align: center; color: green;" >         neveropen     </ h1 >       < h3 style = "text-align: center;" >         D3.js | d3.area.x() Method     </ h3 >       < center >         < svg id = "gfg" width = "200" height = "200" >         </ svg >     </ center >       < script >         var data = [           {x: 50, y: 10},           {x: 150, y: 30},           {x: 200, y: 150},           {x: 250, y: 10},           {x: 300, y: 150},           {x: 350, y: 50},           {x: 400, y: 190}];           var xScale =  d3.scaleLinear().domain([0, 8]).range([25, 200]);         var yScale = d3.scaleLinear().domain([0, 20]).range([200, 25]);           var Gen = d3.area()           // Using area.x() method           .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:
<!DOCTYPE html> < html > < head >     < meta charset = "utf-8" >       < script src =     </ script > </ head > < body >     < h1 style = "text-align: center; color: green;" >         neveropen     </ h1 >       < h3 style = "text-align: center;" >         D3.js | d3.area.x() Method     </ h3 >       < center >         < svg id = "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}];             var Gen = d3.area()            // Using area.x() method           .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: