Created
January 7, 2018 03:40
-
-
Save NPashaP/6908ba59bcfd51ba872a35a20bb5842f to your computer and use it in GitHub Desktop.
Viz - Area - Stacked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<style> | |
.viz-area .area{ | |
fill: steelblue; | |
stroke: none; | |
} | |
</style> | |
<body> | |
<svg width="960" height="600"> | |
<g transform="translate(50,50)"></g> | |
</svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="http://vizjs.org/viz.v1.3.0.min.js"></script> | |
<script> | |
var fill = ["#880E4F", "#AD1457", "#F06292", "#F48FB1"]; | |
var data = randomData(); | |
var stack = d3.stack() | |
.keys(["value1","value2","value3","value4"]) | |
(data) | |
var area = viz.area() | |
.key(function(d){ return d.data.key}) | |
.value0(function(d){ return d[0]}) | |
.value1(function(d){ return d[1]}) | |
.keyScale(d3.scaleLinear().domain([0,20]).range([0,880])) | |
.valueScale(d3.scaleLinear().domain([0,4]).range([420,0])) | |
.curve(d3.curveCardinal) | |
var areas = d3.select("g") | |
.selectAll(".areas") | |
.data(stack) | |
.enter() | |
.append("g") | |
.attr("class","areas") | |
.append("path") | |
.attr("d",function(d){ return area.data(d).path()}) | |
.style("fill",function(d,i){ return fill[i]}) | |
function randomData(){ | |
return d3.range(20).map(function(i){ return {key:i, value1: Math.random(), value2: Math.random(), value3: Math.random(), value4: Math.random()}; }); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment