script type text javascript src https d3js org d3 v7 min js script script src https cdn jsdelivr net npm d3 selection 3 script script src https cdn jsdelivr net npm d3 collection script for d3 nest script src https d3js org d3 hexbin v0 2 min js script style hexagon stroke 000 stroke width 0 5px style svg width 600 height 600 svg script var svg d3 select svg var margin top 20 right 20 bottom 20 left 20 var width svg attr width margin left margin right var height svg attr height margin top margin bottom var g svg append g attr transform translate margin left margin top var randomX d3 randomNormal width 2 80 var randomY d3 randomNormal height 2 80 var points d3 range 2000 map function return randomX randomY var color d3 scaleSequential d3 interpolateLab white steelblue domain 0 20 var hexbin d3 hexbin radius 20 extent 0 0 width height var x d3 scaleLinear domain 0 width range 0 width var y d3 scaleLinear domain 0 height range height 0 g append clipPath attr id clip append rect attr width width attr height height g append g attr class hexagon attr clip path url clip selectAll path data hexbin points enter append path attr d hexbin hexagon attr transform function d return translate d x d y attr fill function d return color d length g append g attr class axis axis y call d3 axisLeft y tickSizeOuter width g append g attr class axis axis x attr transform translate 0 height call d3 axisBottom x tickSizeOuter height console log ready script
0 var hexbin d3 hexbin radius 20 extent 0 0 width height var x d3 scaleLinear domain 0 width range 0 width var y d3 scaleLinear domain 0 height range height 0 g append clipPath attr id clip append rect attr width width attr height height g append g attr class hexagon attr clip path url clip selectAll path data hexbin points enter append path attr d hexbin hexagon attr transform function d return translate d x d y attr fill function d return color d length g append g attr class axis axis y call d3 axisLeft y tickSizeOuter width g append g attr class axis axis x attr transform translate 0 height call d3 axisBottom x tickSizeOuter height console log ready script