Published
Edited
Sep 9, 2020
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
groceryList = []
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
list = {
var groceryList = []
groceryList.push("apples")
groceryList.push("bananas")
groceryList.push("coffee")
return groceryList
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
list[1]
Insert cell
Insert cell
list[0]
Insert cell
Insert cell
listOfThings = ["item1", 42, 3.14, ["pb","j"]]
Insert cell
Insert cell
Insert cell
listOfThings[0]
Insert cell
Insert cell
listOfThings[1]
Insert cell
Insert cell
listOfThings[2]
Insert cell
Insert cell
listOfThings[3]
Insert cell
Insert cell
Insert cell
drawingCircles = [3, 5, 5, 6, 15, 18]
Insert cell
Insert cell
Insert cell
d3 = require('d3')
Insert cell
{
const width = 600
const height = 400
const canvas = d3.select(DOM.svg(width, height))
canvas.append("circle")
.attr("cx", 160)
.attr("cy", 280)
.attr("r", 80)
return canvas.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
{
const width = 600
const height = 400
const canvas = d3.select(DOM.svg(width, height))
// Observe
canvas.selectAll("circle")
// Collect
.data(drawingCircles)
// Update
.join("circle")
.attr("cx", 160)
.attr("cy", 280)
.attr("r", 80)
return canvas.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
{
const width = 600
const height = 400
const canvas = d3.select(DOM.svg(width, height))

// Observe
canvas.selectAll("circle")
// Collect
.data(drawingCircles)
// Update
.join("circle")
.attr("cx",
function(d,i) {
return i*20
}
)
.attr("cy", 280)
.attr("r",
function(d,i) {
return d
}
)
return canvas.node();
}
Insert cell
Insert cell
{
const width = 600
const height = 400
const canvas = d3.select(DOM.svg(width, height))
// Observe
canvas.selectAll("circle")
// Collect
.data(drawingCircles)
// Update
.join("circle")
.attr("cx", (d,i)=> i*20)
.attr("cy", 280)
.attr("r", (d,i)=> d)
return canvas.node();
}
Insert cell
Insert cell
{
const width = 600
const height = 400
const canvas = d3.select(DOM.svg(width, height))
canvas.selectAll("circle")
.data(drawingCircles)
.join("circle")
.attr("cx", (d,i)=> i*30)
.attr("cy", (d,i)=> i*20)
.attr("r", (d,i)=> d)
return canvas.node();
}
Insert cell
Insert cell
{
const width = 600
const height = 400
const canvas = d3.select(DOM.svg(width, height))
canvas.selectAll("circle")
.data(drawingCircles)
.join("circle")
.attr("cx", (d,i)=> i*30)
.attr("cy", (d,i)=> height - (i*20))
.attr("r", (d,i)=> d)
return canvas.node();
}
Insert cell
Insert cell
yourCircles = []
Insert cell
{
// define the canvas
// remember 1) Observe 2) Collect 3) Update
// Observe (no circles on the canvas)
// Collect (add yourCircles data)
// Update (update the canvas with your data)
// return your canvas
}
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