D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
henryjameslau
Full window
Github gist
Fill patterns
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; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) data=d3.range(12) svg.selectAll('pattern') .data(data) .enter() .append('pattern') .attr("id",function(d){return "hatch"+d}) .attr("patternUnits","userSpaceOnUse") .attr("patternTransform",function(d){return "rotate("+(d*15)+ " 0 0)"}) .attr("width",4) .attr("height",4) .append("line") .attr("x1",0) .attr("y1",0) .attr("x2",0) .attr("y2",2) .style("stroke","black") .style("stroke-width",1) svg.selectAll('rect') .data(data) .enter() .append('rect') .attr("y", 70) .attr("x", function(d){return d*70+20}) .attr("width",50) .attr("height",50) .attr("fill",function(d){return "url(#hatch"+d+")"}) .attr("stroke","black") .attr("stroke-width","1") </script> </body>
https://d3js.org/d3.v4.min.js