D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
chowzzzz
Full window
Github gist
D3 Fundamentals - Drawing with Data
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <title>Drawing SVG Shapes with D3</title> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> var w = 200; var h = 100; var padding = 2; var dataset = [5, 10, 15, 20, 25]; var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h) svg.selectAll("rect") // Take all the rect and create new ones .data(dataset) // for all the diff elements in dataset .enter() // If there aren't any on the page, create them .append("rect") // Append rect .attr("x", function(d, i) { // Access data and index of dataset array return i * (w / dataset.length); }) .attr("y", function(d) { return h - (d * 4); }) .attr("width", w / dataset.length - padding) .attr("height", function(d) { return d * 4; }) .style("fill", "darkseagreen"); </script> </body>
https://d3js.org/d3.v4.min.js