Public
Edited
Jul 9, 2024
6 forks
Insert cell
Insert cell
data1 = d3.tsv(
"https://gist.githubusercontent.com/rayhong/cfbf3efb9879ee43babe6d41429ca487/raw/746c404066d7cfc3238108c7b03e6f93b8f4f602/bar.tsv"
)
Insert cell
data = data1.slice(0, 10)
Insert cell
Insert cell
height = 400
Insert cell
x = d3
.scaleBand()
.domain(data.map((d) => d.letter))
.range([margin.left, width - margin.right])
.padding(0.1)
Insert cell
y = d3
.scaleLinear()
.domain([0, d3.max(data, (d) => d.frequency)])
.range([height - margin.bottom, margin.top])
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height));

svg
.append("g")
.attr("fill", "steelblue")
.selectAll()
.data(data)
.join("rect")
.attr("x", (d) => x(d.letter))
.attr("y", (d) => y(d.frequency))
.attr("height", (d) => y(0) - y(d.frequency))
.attr("width", x.bandwidth());
return svg.node();
}
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