Wednesday, July 3, 2024
HomeLanguagesJavascriptD3.js area.y0() method

D3.js area.y0() method

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;">
        neveropen
    </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;">
        neveropen
    </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:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments