Area generator (with baseline).
From D3 in Depth book by Peter Cook.
license: gpl-3.0 | |
height: 160 | |
border: no |
Area generator (with baseline).
From D3 in Depth book by Peter Cook.
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<head> | |
<title>Area generator (with baseline)</title> | |
</head> | |
<style> | |
path { | |
fill: #ddd; | |
} | |
</style> | |
<body> | |
<svg width="700" height="150"> | |
<g></g> | |
</svg> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> | |
<script> | |
var areaGenerator = d3.area().y0(150); | |
var points = [ | |
[0, 80], | |
[100, 100], | |
[200, 30], | |
[300, 50], | |
[400, 40], | |
[500, 80] | |
]; | |
var area = areaGenerator(points); | |
// Create a path element and set its d attribute | |
d3.select('g') | |
.append('path') | |
.attr('d', area); | |
</script> | |
</body> | |
</html> |