Public
Edited
Oct 26, 2023
4 forks
8 stars
Insert cell
Insert cell
Insert cell
Insert cell
FileAttachment("numbers.csv").text()
Insert cell
Insert cell
d3.csvParse(await FileAttachment("numbers.csv").text())
Insert cell
Insert cell
Insert cell
d3.csvParse(await FileAttachment("numbers.csv").text(), d3.autoType)
Insert cell
Insert cell
data = FileAttachment("numbers.csv").csv({typed: true})
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.value)])
.range([0, width])
Insert cell
y = d3.scaleBand()
.domain(data.map(d => d.name))
.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.name)})`);

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

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

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