Open In App

D3.js area.y0() method

Improve
Improve
Like Article
Like
Save
Share
Report

The d3.area.y0() method is used to set the y0 accessor to the argument passed to it which may be either a number or a function that returns a number, this is the first point or our lower bounds.

Syntax:

d3.area.y0(y0_point)

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

  • y0_point: This parameter is a number lower bound 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;">
        GeeksforGeeks
    </h1>
  
    <h3 style="text-align: center;">
        D3.js | d3.area.y0() 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()
          .x((p) => p.x)
          // Using area.y0() method
          .y0((p) => p.y*2)
          .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;">
        GeeksforGeeks
    </h1>
  
    <h3 style="text-align: center;">
        D3.js | d3.area.y0() 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()
          .x((p) => p.xpoint)
          // Setting lower bounds to 0
          .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:



Last Updated : 07 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads