Published unlisted
Edited
Feb 28, 2020
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);
let bars = 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));
bars.on("mouseover", function(d) {
bars.filter(e => (d.letter !== e.letter)).transition().attr("fill-opacity", ".4");
});
bars.on("mouseout", function(d) {
bars.transition().attr("fill-opacity", "1");
});
// 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

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