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) svg.append('pattern') .attr("id","hatch1") .attr("patternUnits","userSpaceOnUse") .attr("patternTransform","rotate(45 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.append('pattern') .attr("id","hatch2") .attr("patternUnits","userSpaceOnUse") .attr("patternTransform","rotate(-45 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.append('pattern') .attr("id","hatch3") .attr("patternUnits","userSpaceOnUse") .attr("patternTransform","rotate(-90 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.append('pattern') .attr("id","hatch4") .attr("patternUnits","userSpaceOnUse") .attr("patternTransform","rotate(00 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) data=d3.range(5) svg.selectAll('rect') .data(data) .enter() .append('rect') .attr("y", 70) .attr("x", function(d){return d*100+20}) .attr("width",50) .attr("height",50) .attr("fill",function(d){return "url(#hatch"+d+")"}) </script> </body>
https://d3js.org/d3.v4.min.js