nick34992
3/8/2017 - 11:06 PM

D3byEX 9.1: Line Generator (Adapted to D3.js v4)

D3byEX 9.1: Line Generator (Adapted to D3.js v4)

<!DOCTYPE html>
<html>
    <meta charset=utf-8>
<head>
    <meta name="description" content="D3.js v4, line sequence, SVG
                                      container" />
</head>

<body>
    <script src="http://d3js.org/d3.v4.min.js"></script>
    <script src="https://d3js.org/d3-selection-multi.v1.min.js"></script>
    <script>

        var svg = d3.select('body')
                    .append('svg')
                    .attrs({ width: 500, height: 250 });

        var data = [ { X: 10, Y: 10 }, { X: 60, Y: 60 }, { X: 80, Y: 20 } ];

        var generator = d3.line()
                          .x(function (d) { return d.X; })
                          .y(function (d) { return d.Y; });

        svg.append('path')
           .datum(data)
           .attrs({ d: generator, stroke: 'steelblue' });

        svg.append('path')
           .datum(data)
           .attrs({ transform: 'translate(100,0)', d: generator,
                    fill: 'none', stroke: 'steelblue'
           });

    </script>
</body>
</html>