Published
Edited
Feb 27, 2020
6 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height))
.attr("id", "chart");
svg.append("g")
.attr("id", "x-axis")
.attr("transform", `translate(${margin.left}, ${height - margin.bottom})`)
.call(xaxis);
svg.append("g")
.attr("id", "y-axis")
.attr("transform", `translate(${margin.left}, ${margin.top})`)
.call(yaxis);
svg.append("g")
.attr("id", "bars")
.attr("transform", `translate(${margin.left}, ${margin.top})`)
.selectAll("rect")
.data(letters)
.enter()
.append("rect")
.attr("x", d => x(d.letter))
.attr("y", d => y(d.frequency))
.attr("width", x.bandwidth())
.attr("height", d => innerHeight - y(d.frequency));
// TODO Add your interactivity code here or in another cell.
return svg.node();
}
Insert cell
Insert cell
x = d3.scaleBand()
.domain(letters.map(d => d.letter))
.range([0, innerWidth])
.paddingInner(0.2)
.paddingOuter(0.1);
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(letters, d => d.frequency)])
.range([innerHeight, 0])
.nice();
Insert cell
xaxis = d3.axisBottom(x)
.tickSize(0)
.tickPadding(5);
Insert cell
yaxis = d3.axisLeft(y)
.tickValues(y.domain())
.tickPadding(5);
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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