D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
marijer
Full window
Github gist
linechart
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; } path { stroke: #000; stroke-width: 1px; fill: none; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var data = [ {date: new Date(2017, 3, 24), value: 0}, {date: new Date(2017, 3, 25), value: 9}, {date: new Date(2017, 3, 26), value: 25}, {date: new Date(2017, 3, 27), value: 50}, {date: new Date(2017, 3, 28), value: 12} ]; var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500); var xExtent = d3.extent(data, d => d.date); var yExtent = d3.extent(data, d => d.value); var xScale = d3.scaleLinear().domain(xExtent).range([0, 400]); var yScale = d3.scaleLinear().domain(yExtent).range([200, 0]); var line = d3.line() .x((d) => { return xScale(d.date)}) .y((d) => { return yScale(d.value)}) svg.append('path') .attr('d', line(data)); </script> </body>
https://d3js.org/d3.v4.min.js