D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
basilesimon
Full window
Github gist
Test 2,000 dots in browser for sanity
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; } body { padding: 2em;} body { background-color: #F8F7F1;} </style> </head> <body> <script> const config = { width: 600, height: 400 }; const svg = d3.select("body").append("svg") .attr("width", config.width) .attr("height", config.height) const x = d3.scaleTime() .range([0, config.width]); const y = d3.scaleLinear() .range([config.height, 0]); const xExtent = [new Date('2015-12-31'), new Date()]; const yExtent = d3.extent([0,50]); x.domain(xExtent); y.domain(yExtent); d3.json('polls.json', function(err, data) { const parseDate = d3.timeParse('%Y-%m-%d'); data.forEach((d, i) => d.date = parseDate(d.date) ); data.forEach(function(d, i, o) { if (d.poll != 'NA') { d.date = new Date(d.date); d.poll = +d.poll; } else { o.splice(i, 1); } }); svg.selectAll('circle') .data(data).enter() .append('circle') .attr('cx', d => x(d.date)) .attr('cy', d => y(d.poll)) .attr('r', 4) .style('opacity', .2) }) </script> </body>
https://d3js.org/d3.v4.min.js