Notebooks 2.0 is here.

Published
Edited
Jul 12, 2021
Insert cell
Insert cell
Insert cell
Insert cell
FileAttachment("test.csv").text()
Insert cell
Insert cell
d3.csvParse(await FileAttachment("test.csv").text())
Insert cell
Insert cell
data = d3.csvParse(await FileAttachment("test.csv").text(), d3.autoType)
Insert cell
Insert cell
"1" + "2" // not 3
Insert cell
d3.max(["1", "2", "10"]) // not "10"
Insert cell
Insert cell
x = d3.scaleLinear()
.domain([0, d3.max(data, d => d.count)])
.range([0, width])
Insert cell
y = d3.scaleBand()
.domain(data.map(d => d.shape))
.range([0, 20 * data.length])
Insert cell
{
const svg = d3.create("svg")
.attr("width", width)
.attr("height", y.range()[1])
.attr("font-family", "sans-serif")
.attr("font-size", "10")
.attr("text-anchor", "end");

const bar = svg.selectAll("g")
.data(data)
.join("g")
.attr("transform", d => `translate(0,${y(d.shape)})`);

bar.append("rect")
.attr("fill", "steelblue")
.attr("width", d => x(d.count))
.attr("height", y.bandwidth() - 1);

bar.append("text")
.attr("fill", "white")
.attr("x", d => x(d.value) - 3)
.attr("y", y.bandwidth() / 2)
.attr("dy", "0.35em")
.text(d => d.value);

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