Public
Edited
Jun 5, 2024
7 forks
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
<svg width="950" height="160">
<path d="M 10 50 L 100 20 L 200 80 L 500 20 L 700 20 L 750 0 " fill="None" stroke="#131B26"/></path>
</svg>
Insert cell
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

svg.append("path").datum(data).attr("class", "line").attr("d", line);

return svg.node();
}
Insert cell
Insert cell
x = d3.scaleTime()
.domain(d3.extent(data, d => d.date))
.range([margin.left, width - margin.right])
Insert cell
y = d3
.scaleLinear()
.domain(d3.extent(data, (d) => d.Addiction))
.range([height - margin.bottom, margin.top])
Insert cell
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.attr("class","y-axis")
.call(d3.axisLeft(y)
.tickValues([0, 10, 20])
.tickSize(-width))
Insert cell
Insert cell
Insert cell
line = d3.line()
.defined(d => d.Addiction > 0)
.x(d => x(d.date))
.y(d => y(d.Addiction))
Insert cell
line(data)
Insert cell
Insert cell
data = d3.tsvParse(await FileAttachment("search@1.tsv").text(), ({date, Addiction}) => ({date: parseDate(date), Addiction: +Addiction}))
Insert cell
data_raw = d3.tsvParse(await FileAttachment("search@1.tsv").text())
Insert cell
parseDate = d3.timeParse("%m%Y")
Insert cell
formatDate = d3.timeFormat("%b%y");
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