D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
35degrees
Full window
Github gist
myLbs
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body </style> </head> <body> <script> var margin = {top: 20, right: 20, bottom: 100, left: 50}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var parseTime = d3.timeParse("%d-%b-%y"); var x = d3.scaleTime().range([0, width]); var y = d3.scaleLinear().range([height, 0]); var valueline = d3.line() .curve(d3.curveBasis) .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.lbs); }); 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 + ")"); d3.tsv("myLbs.tsv",function(error,data){ if (error) throw error; data.forEach(function(d){ d.date = parseTime(d.date) d.lbs = +d.lbs; }); x.domain(d3.extent(data, function(d){ return d.date})); y.domain([200, d3.max(data, function(d) { return d.lbs; })]); svg.append('path') .data([data]) .attr('class','line') .attr('d',valueline) svg.append("g") .attr("class","axis") .attr("transform", "translate(0," + height + ")") .call(d3.axisBottom(x).ticks(12)); svg.append("g") .attr("class","axis") .call(d3.axisLeft(y) ); }); </script> </body>
https://d3js.org/d3.v4.min.js