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.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!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;">GeeksforGeeks</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>

chevron_right


Output:

Example 2: Making a Multiconnected line.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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;">GeeksforGeeks</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>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.