nick34992
3/9/2017 - 1:31 AM

D3byEX 9.2: Area Generator (Adapted to D3.js v4)

D3byEX 9.2: Area Generator (Adapted to D3.js v4)

<!DOCTYPE html>
<html>
    <meta charset=utf-8>
<head>
    <meta name="description" content="D3.js v4, line graph area" />
</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>

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

        var data = d3.range(100)
                     .map(function (i) { return Math.random() * 30; })
                     .map(function (d, i) { return { X: i * 10, Y: d } });

        var generator = d3.area()
                          .y0(100)
                          .x(function (d) { return d.X; })
                          .y1(function (d) { return d.Y; });

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

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