Published
Edited
Mar 1, 2022
5 forks
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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more