Liveweave: Generative AI Web Editor & HTML/CSS/JS Playground
Initializing
Liveweave
Web
expand_more
home
Home
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
frame_source
Python Playground
arrow_outward
build
Tools
expand_more
restart_alt
Load "Hello Weaver!"
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Fork
account_circle
Login
settings
Settings
expand_more
Editor font
14
px
A
A
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
left_panel_close
AI Assistant
dashboard
All
HTML
CSS
JS
visibility
Preview
bolt
Live Preview
terminal
JS Console
<!DOCTYPE html> <html> <head> <title>D3 Hexbin Chart</title> <!-- Load d3.js --> <script src="https://d3js.org/d3.v4.js"></script> <!-- specific plugin --> <script src="https://d3js.org/d3-hexbin.v0.2.min.js"></script> </head> <body> <!-- Start your code here --> <div id="my_dataviz"></div> <!-- End your code here --> </body> </html>
.lw { font-size: 60px; }
// set the dimensions and margins of the graph var margin = {top: 10, right: 30, bottom: 30, left: 40}, width = 460 - margin.left - margin.right, height = 400 - margin.top - margin.bottom; // append the svg object to the body of the page var svg = d3.select("#my_dataviz") .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 + ")"); // read data d3.csv("https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/data_for_density2d.csv", function(data) { // Add X axis var x = d3.scaleLinear() .domain([5, 18]) .range([ 0, width ]); svg.append("g") .attr("transform", "translate(0," + height + ")") .call(d3.axisBottom(x)); // Add Y axis var y = d3.scaleLinear() .domain([5, 20]) .range([ height, 0 ]); svg.append("g") .call(d3.axisLeft(y)); // Reformat the data: d3.hexbin() needs a specific format var inputForHexbinFun = [] data.forEach(function(d) { inputForHexbinFun.push( [x(d.x), y(d.y)] ) // Note that we had the transform value of X and Y ! }) // Prepare a color palette var color = d3.scaleLinear() .domain([0, 600]) // Number of points in the bin? .range(["transparent", "#69b3a2"]) // Compute the hexbin data var hexbin = d3.hexbin() .radius(9) // size of the bin in px .extent([ [0, 0], [width, height] ]) // Plot the hexbins svg.append("clipPath") .attr("id", "clip") .append("rect") .attr("width", width) .attr("height", height) svg.append("g") .attr("clip-path", "url(#clip)") .selectAll("path") .data( hexbin(inputForHexbinFun) ) .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); }) .attr("stroke", "black") .attr("stroke-width", "0.1") })
terminal
JavaScript Console
Preview
Clear
close
›
Run