Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptD3.js line.x() method

D3.js line.x() method

The d3.line.x() method sets or gets the x accessor point of the line. If x is provided, it must be a number or a function that returns a number.

Syntax:

d3.line.x(x-point);

Parameters:

  • x-point: This method takes an x-point that can be set from the points array.

Return Value: This method returns the x accessor point of the line.

Example 1: Setting the x-point using this method. For y-points here we have used line.y() function.




<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
  <title>Line in D3.js</title>
</head>
<script src=
</script>
  
<body>
    <h1 style="text-align: center;
               color: green;">
         neveropen
   </h1>
  <center>
    <svg id="gfg" width="200" height="200">
  </svg>
</center>
  <script>
var points = [
  {xpoint: 25,  ypoint: 150},
  {xpoint: 75,  ypoint: 85},
  {xpoint: 100, ypoint: 115},
  {xpoint: 175, ypoint: 25}];
  
var Gen = d3.line()
  // Setting the x-point
  .x((p) => p.xpoint)
  .y((p) => p.ypoint);
  
d3.select("#gfg")
  .append("path")
  .attr("d", Gen(points))
  .attr("fill", "none")
  .attr("stroke", "green");
</script>
</body>
</html>


Output:

Example 2: getting the function for x points.




<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
  <title>Line in D3.js</title>
</head>
<script src=
</script>
  
<body>
    <h1 style="text-align: center; color: green;">
       neveropen
    </h1>
  <center>
    <svg id="gfg" width="200" height="200"></svg>
</center>
  <script>
var points = [
  {xpoint: 25,  ypoint: 150},
  {xpoint: 75,  ypoint: 85},
  {xpoint: 100, ypoint: 115},
  {xpoint: 175, ypoint: 25}];
  
var Gen = d3.line()
  .x((p) => p.xpoint)
  .y((p) => p.ypoint);
  
d3.select("#gfg")
  .append("path")
  .attr("d", Gen(points))
  .attr("fill", "none")
  .attr("stroke", "green");
console.log(Gen.x());
console.log(Gen.x)
</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!

RELATED ARTICLES

Most Popular

Recent Comments