D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
sarubenfeld
Full window
Github gist
2016: AMZN Stock Market Close
<!DOCTYPE html> <meta charset="utf-8"> <style> body { font-family: Futura; font-size: 10px; } div { display: inline-block; } h1 { font-family: futura; font-size: 16px; align-self: auto; } .axis { stroke-dasharray: 2, 2; stroke-linecap: "round"; shape-rendering: crispEdges; } .area { fill: url(#area-gradient); stroke-width: 0px; } .axis line { stroke: #ccc; stroke-dasharray: 1px 1px; } text { font-family: Futura; } </style> <body> <div class="g-chart-container"> <h1> 2016: AMZN Stock Market Close </h1> </div> </body> <script src="https://d3js.org/d3.v4.min.js"></script> <script> var margin = {top: 20, right: 20, bottom: 30, left: 50}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var parseTime = d3.timeParse("%Y-%m-%d"); var x = d3.scaleTime().range([0, width]); var y = d3.scaleLinear().range([height, 0]); var area = d3.area() .x(function(d) { return x(d.date); }) .y0(height) .y1(function(d) { return y(d.close); }); d3.csv("amazon.csv", function(error, data) { if (error) throw error; data.forEach(function(d) { d.date = parseTime(d.date); d.close = +d.close; }); x.domain(d3.extent(data, function(d) { return d.date; })); y.domain([0, d3.max(data, function(d) { return d.close; })]); var colours = ["#700961","#B80D57","#E03E36","#FF7C38"]; svg.append("linearGradient") .attr("id", "area-gradient") .attr("gradientUnits", "userSpaceOnUse") .attr("spreadMethod", "reflect") .style("mix-blend-mode","overlay") .attr("x1", 0).attr("y1", y(0)) .attr("x2", 0).attr("y2", y(900)) .selectAll("stop") .data(colours) .enter().append("stop") .attr("offset", function(d,i) { return i/(colours.length-1); }) .attr("stop-color", function(d) { return d; }); svg.append("path") .data([data]) .attr("class", "area") .attr("d", area); svg.append("g") .attr("transform", "translate(0," + height + ")") .call(d3.axisBottom(x)); svg.append("g") .call(d3.axisLeft(y)); }); </script>
https://d3js.org/d3.v4.min.js