D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
tcwood
Full window
Github gist
d3-shapes
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; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var data = [ {date: new Date(2007, 3, 24), value: 9}, {date: new Date(2007, 3, 25), value: 9}, {date: new Date(2007, 3, 26), value: 9}, {date: new Date(2007, 3, 27), value: 9}, {date: new Date(2007, 3, 30), value: 9}, {date: new Date(2007, 4, 1), value: 9}, ] var margins = {top: 20, right: 20, bottom: 20, left: 20}; var height = 300; var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) var xExtent = d3.extent(data, d => d.date); var yMax = d3.max(data, d => d.value); var xScale = d3.scaleTime() .domain(xExtent) .range([margins.left, margins.right]); var yScale = d3.scaleLinear() .domain([0, yMax]) .range([margins.top, height - margins.top -margins.bottom]); var line = d3.line() .x(d => xScale(d.date)) .y(d => yScale(d.value)) svg.append('path') .attr('d', line(data)) .attr('stroke', 'blue'); // svg.append("text") // .text("Edit the code below to change me!") // .attr("y", 200) // .attr("x", 120) // .style("font-size", 36) // .style("font-family", "monospace") console.log(line(data)); </script> </body>
https://d3js.org/d3.v4.min.js