Open In App

D3.js area.y1() method

Last Updated : 07 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax:

d3.area.y1(y1_point)

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

  • y1_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.y1() 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)
          .y0((p) => p.y*2)
          // Using area.y1() method
          .y1((p) => p.y*4);
  
        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.y1() 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)
          .y0((p) => p.ypoint/2)
          // Setting upper bounds
          .y1((p) => p.ypoint);
  
        d3.select("#gfg")
          .append("path")
          .attr("d", Gen(points))
          .attr("fill", "green")
          .attr("stroke", "black");
  
    </script>
</body>
  
</html>


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads