Public
Edited
Nov 30, 2022
Insert cell
Insert cell
Insert cell
Insert cell
d3tip = require("d3-tip")
Insert cell
width = 1500
Insert cell
height = 500
Insert cell
step = (width-margin.right-margin.left)/15;
Insert cell

x = d3.scaleOrdinal()
.domain(["", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"])
.range(d3.range(margin.left, margin.left + 9*step, step));
Insert cell
y = d3.scaleLinear()
.domain([0, data.reduce((acc, value) => {
return (acc = acc > value.y ? acc : value.y);
}, 0) + 0.5])
.range([height-margin.bottom, margin.top])
Insert cell
xAxis = g => g
.attr("id", "axis")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).tickSizeOuter(0))
.attr("opacity", "0")
.selectAll("text")
.attr("transform", "translate(10,0)rotate(-45)")
.style("text-anchor", "end")
.style("font-size", 16)
.style("fill", "#69a3b2")
Insert cell
yAxis = g => g
.attr("id","yaxis")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).tickSizeOuter(0))
.attr("opacity", "0")
.selectAll("text")
.style("text-anchor", "end")
.style("font-size", 16)
.style("fill", "#69a3b2")
Insert cell
data[14]["name"]
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
myColor = d3.scaleOrdinal()
.domain(["a","b","c"])
.range(["#CC333F","#00A0B0", "#EDC951"]);
Insert cell
popularComp = FileAttachment("Popular-Comp.json").json()
Insert cell
myColor("first")
Insert cell
margin = ({top: 25, right: 20, bottom: 75, left: 50})
Insert cell
d3 = require("d3@6")
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