D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
jwilber
Full window
Github gist
streamgraph d3ia
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } svg { border: 1px dotted red; } </style> </head> <svg width="800" height="600"></svg> <body> <script> d3.csv('movies.csv', dataViz); function dataViz(data){ console.log(data); var xScale = d3.scaleLinear().domain([0, 10]).range([0, 800]); var movies = ['titanic', 'avatar', 'akira', 'frozen', 'deliverance', 'avengers']; var fillScale = d3.scaleOrdinal() .domain(movies) .range(['red', 'orange', 'yellow', 'coral', 'blue', 'grey']); stackLayout = d3.stack() .keys(movies) // .offset(d3.stackOffsetWiggle) .offset(d3.stackOffsetSilhouette).order(d3.stackOrderInsideOut); var stacked = stackLayout(data); var yScale = d3.scaleLinear() .domain([ d3.min(stacked, function (series) { return d3.min(series, function (d) { return d[0]; }); }), d3.max(stacked, function (series) { return d3.max(series, function (d) { return d[1]; }); }) ]) .range([500, 0]); var stackArea = d3.area() .x((d, i) => xScale(i)) .y0(d => yScale(d[0])) .y1(d => yScale(d[1])) .curve(d3.curveBasis); d3.select('svg').selectAll('path') .data(stacked) .enter().append('path') .style('fill', d => fillScale(d.key)) .style('stroke', 'black') .attr('d', d => stackArea(d)); } </script> </body>
https://d3js.org/d3.v4.min.js