D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
AlexDaGr8
Full window
Github gist
Color Scale
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v5.min.js"></script> </head> <body> <script> var margin = {left: 20, top: 20, right: 40, bottom: 20}, width = 950 - 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] + ')'); console.log('width', width) var data = []; for (var i=0; i<40; i++) { data.push(i) } var x = d3.scalePoint() .range([0,width]) .domain(data.map(d => d)) .padding(0.05); var rainbow = d3.scaleSequential(d3.interpolatePiYG) .domain(d3.extent(data,d=>d)); svg.selectAll('rect') .data(data) .enter().append('rect') .attr('x', d => x(d)) .attr('y', height/2 - 50) .attr('width', x.step()) .attr('height', 100) .attr('fill', d => rainbow(d)) </script> </body>
https://d3js.org/d3.v5.min.js