Published
Edited
May 25, 2020
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
const timeParser = d3.timeParse("%d %b %Y");
const csvString = await FileAttachment("Cells in Journal_ Getting Started with Data Viz - Journal cells - 25 May 2020.csv").text();
let accumulator = 0;
const rowConversionFunction = ({
"Title": title,
"URL": url,
"Number of cells": y,
"Date": x
}) => {
return {
title,
url,
x: timeParser(x),
y: +y,
yCumulative: accumulator = accumulator + +y // This!
}
};
const dataObjectTarget = d3.csvParse(csvString, rowConversionFunction);
const extraPropertiesSource = {x: "Date →", y: "↑ Cells"};
return Object.assign(dataObjectTarget, extraPropertiesSource);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
x = d3.scaleUtc()
.domain(d3.extent(data, d => d.x))
.range([margin.left, width - margin.right]);
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0))
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.yCumulative)]).nice()
.range([height - margin.bottom, margin.top]);
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.select(".tick:last-of-type text").clone()
.attr("x", 3)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(data.y))
Insert cell
area = d3.area()
.curve(curve)
.x(d => x(d.x))
.y0(y(0))
.y1(d => y(d.yCumulative));
Insert cell
curve = d3.curveLinear;
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