Public
Edited
Apr 15, 2023
Insert cell
Insert cell
names = ["Eric","Vinay","Chase","Lucy"]
Insert cell
numbers = [1,2,3,4,5,6,7]
Insert cell
Insert cell
<svg width="800" height="200"></svg>
Insert cell
Insert cell
mySVG = d3.select(svgObject)
Insert cell
Insert cell
mySVG.selectAll("rect")
.data(numbers)
.join("rect")
.attr("width", d => d * 5) // given d (the data element from numbers) give me back d times 5
.attr("height",d => d * 5)
.attr("x", d => d * spacing)
.attr("y", 50)
Insert cell
spacing = 50 // this is just a variable to illustrate that we can use it in the code above and below.
Insert cell
Insert cell
mySVG.selectAll("text")
.data(names)
.join("text")
.text(d => d)
.attr("y", 40)
.attr("x", (d,i) => i * spacing + spacing)
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more