Published
Edited
Jan 15, 2021
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("g")
.attr("fill", "pink")
.selectAll("rect")
.data(data)
.join("rect")
.attr("y", (d, i) => y(i))
.attr("x", 0)
.attr("width", width)
.attr("height", y.bandwidth())
svg.append("g")
.attr("fill", "skyblue")
.selectAll("rect")
.data(data)
.join("rect")
.attr("y", (d, i) => y(i))
.attr("x", d => 0)
.attr("width", d => x(d.CASE_RATE_PER_100K))
.attr("height", y.bandwidth());

return svg.node();
}
Insert cell
data = JSON.parse(await FileAttachment("social-income@1.json").text()).sort((a,b) => {
return parseInt(a.SORT) - parseInt(b.SORT)
})
Insert cell
y = d3.scaleBand()
.domain(d3.range(data.length))
.range([margin.left, height])
.padding(0.1)
Insert cell
x = d3.scaleLinear()
.domain([0, d3.max(data, d => d.CASE_RATE_PER_100K)]).nice()
.range([0, width])
Insert cell
height = 500
Insert cell
margin = ({top: 30, right: 0, bottom: 30, left: 10})
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