Public
Edited
Feb 12, 2023
2 forks
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("g")
.call(xAxis);

svg.append("g")
.call(yAxis);

svg.append("g")
.selectAll("circle")
.data(data)
.join("circle")
.filter(d => d.individuals_affected)
.attr("cx", d => x(new Date(d.breach_submission_date)))
.attr("cy", d => y(d.individuals_affected))
.attr("r", d => z(d.individuals_affected))
.attr('fill','steelblue')
.attr('opacity',0.2);

svg.append('path')
.attr('d', line(startend90))
.attr('stroke', 'red')

svg.append('path')
.attr('d', line(startend99))
.attr('stroke', 'red')
return svg.node();
}
Insert cell
data = FileAttachment("health_breaches_storyboard_data.csv").csv({typed: true})
Insert cell
health_breaches_storyboard_data.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
height = 400
Insert cell
new Date("2009-10-21")
Insert cell
d3.extent(data, d => new Date(d.breach_submission_date))
Insert cell
d3.extent(data, d => d.individuals_affected)
Insert cell
x = d3.scaleTime()
.domain(d3.extent(data, d => new Date(d.breach_submission_date))).nice()
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain(d3.extent(data, d => d.individuals_affected)).nice()
.range([height - margin.bottom, margin.top])
Insert cell
z = d3.scaleLinear()
.domain(d3.extent(data, d => d.individuals_affected)).nice()
.range([ 1, 40]);
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x))
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
Insert cell
margin = ({top: 25, right: 20, bottom: 35, left: 40})
Insert cell
line = d3.line()
.x(d => x(d.breach_submission_date))
.y(d => y(d.individuals_affected));
Insert cell
startend90 = [{breach_submission_date: new Date("2009-10-21"), individuals_affected: 64840.6},{breach_submission_date: new Date("2023-01-03"), individuals_affected: 64840.6}]
Insert cell


startend99 = [{breach_submission_date: new Date("2009-10-21"), individuals_affected: 11500000},{breach_submission_date: new Date("2023-01-03"), individuals_affected: 11500000}]
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