Thursday, September 4, 2025
HomeLanguagesJavascriptD3.js line() method

D3.js line() method

The d3.line() method is used to constructs a new line generator with the default settings. The line generator is then used to make a line.

Syntax:

d3.line();

Parameters: This method takes no parameters.

Return Value: This method returns a line Generator.

Example 1: Making a simple line using this method.




<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
  <title>Line in D3.js</title>
</head>
<script src=
</script>
  
<style>
path {
    fill: none;
    stroke: green;
}
</style>
  
<body>
    <h1 style="text-align: center;
        color: green;">neveropen</h1>
  <center>
    <svg width="500" height="500">
    <path></path>
  </svg>
</center>
  <script>
        // Making a line Generator
        var Gen = d3.line();
        var points = [
            [0, 100],
            [500, 100]
             
        ];
  
        var pathOfLine = Gen(points);
  
        d3.select('path')
            .attr('d', pathOfLine);
  </script>
</body>
</html>


Output:

Example 2: Making a Multiconnected line.




<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
  <title>Line in D3.js</title>
</head>
<script src=
</script>
  
<style>
path {
    fill: none;
    stroke: green;
}
</style>
  
<body>
    <h1 style="text-align: center;
        color: green;">neveropen</h1>
  <center>
    <svg width="500" height="500">
    <path></path>
  </svg>
</center>
  <script>
        // Making a line Generator
        var Gen = d3.line();
        var points = [
            [0, 100],
            [500, 100],
            [200, 200],
            [500, 200]
             
        ];
  
        var pathOfLine = Gen(points);
  
        d3.select('path')
            .attr('d', pathOfLine);
  </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

Dominic
32263 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6627 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS