Skip to content

Instantly share code, notes, and snippets.

@valex
Created November 8, 2017 11:26
Show Gist options
  • Save valex/3f3ff487e9098887efad07453ecb0827 to your computer and use it in GitHub Desktop.
Save valex/3f3ff487e9098887efad07453ecb0827 to your computer and use it in GitHub Desktop.
Areas, d3.js version 4
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</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')
.attr('width', 500)
.attr('height', 250);
var data = d3.range(100) // generate 100 numbers
.map(function (i) {
return Math.random() * 30; // from 0 to 30
})
.map(function (d, i) {
return { X: i * 10, Y: d } // and place its in object
});
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment