Public
Edited
Sep 13, 2023
2 stars
Insert cell
Insert cell
Insert cell
fruits = [
{ name: "🍊", count: 21 },
{ name: "🍇", count: 13 },
{ name: "🍏", count: 8 },
{ name: "🍌", count: 5 },
{ name: "🍐", count: 3 },
{ name: "🍋", count: 2 },
{ name: "🍎", count: 1 },
{ name: "🍉", count: 1 }
]
Insert cell
Insert cell
xScale = d3
.scaleBand()
.domain() // Specify domain
.range() // Specify range
.padding(0.1)
Insert cell
yScale = d3
.scaleLinear()
.domain() // Specify domain
.nice()
.range() // Specify range
Insert cell
Insert cell
xAxis = (g) =>
g
.attr("transform", `translate(,)`) // Specify translation in x and y directions
.call() // Add d3.axisBottom(xScale)
Insert cell
yAxis = (g) =>
g
.attr("transform", `translate(,)`) // Specify translation in x and y directions
.call() // Add d3.axisLeft(yScale)
Insert cell
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

svg
.append("g")
.attr("fill", "steelblue")
.selectAll("rect")
.data(fruits)
.join("rect")
.attr("x", ) // Add xScale(i)
.attr("y", ) // Add yScale(d.count)
.attr("height", ) // Add yScale(...) - yScale(...)
.attr("width", ); // Add <...>.bandwidth()

svg.append("g").call(); // Add xAxis

svg.append("g").call(); // Add yAxis

return svg.node();
}
Insert cell
Insert cell
Insert cell
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