Published
Edited
Jul 2, 2021
1 fork
Insert cell
Insert cell
Insert cell
data = await FileAttachment("response@4.json").json()
Insert cell
Insert cell
datagroup = d3.group(data,data => data.date.slice(0,4))
Insert cell
data2 = await FileAttachment("data.json").json()
Insert cell
subgroups = Object.keys(data2[0]).slice(1)
Insert cell
groups = data2.map(d => d.date)
Insert cell
max = d3.max([0,1])
Insert cell
color = d3.scaleOrdinal()
.domain(subgroups)
.range(['#802bbe','#3c6fbc','#611eb2'])

Insert cell
xSubgroup = d3.scaleBand()
.domain(subgroups)
.range([0, xband.bandwidth()])
.padding([0.05])
Insert cell
xband = d3.scaleBand()
.domain(groups)
.range([75, width - 75])
.padding([0.2])
Insert cell
xAxisband = g => g
.attr("transform", `translate(0, ${height})`)
.call(d3.axisBottom(xband).tickSize(0))
.call(g => g.selectAll("text").attr("transform", "translate(-10,-20)"))
.attr("stroke-opacity", 0);
Insert cell
yband = d3.scaleLinear()
.domain([0, 20])
.range([height - margin.bottom, margin.top]);
Insert cell
yAxisband = g => g
.attr("transform", `translate(${60},0)`)
.call(d3.axisLeft(yband).ticks(null, data.format))
.call(g => g.select(".domain").remove())
.call(g => g.selectAll("line").remove());
Insert cell
height = 700
Insert cell
margin = ({top: 30, right: 0, bottom: 40, left: 40})
Insert cell
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