Published
Edited
May 21, 2021
Insert cell
md`# Temperature Advanced`
Insert cell
interval = 200
Insert cell
year = {
let year = 1864;
while (year < 2018) {
yield Promises.tick(interval, ++year);
}
}
//year = 1864
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height));
svg.append("text")
.attr("x", margin.top)
.attr("y", margin.left)
.text("Monthly temperatures");
svg.append("g")
.append("path")
.datum(data[year - 1864].values)
.attr("fill", "none")
.attr("stroke", color(data[year - 1864].year))
.attr("stroke-width", 2.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", line);
svg.append("text")
.attr("x", x("jan"))
.attr("y", y(data[year - 1864].values[0].value) - 30)
.style("fill", color(data[year - 1864].year))
.text(year);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
return svg.node();
}
Insert cell
line = d3.line()
.curve(d3.curveBasis)
.x(d => x(d.month))
.y(d => y(d.value))
Insert cell
color = d3.scaleSequential(d3.interpolateRdYlBu)
.domain([6, 3])
Insert cell
color(4)
Insert cell
Insert cell
margin = ({top: 50, right: 20, bottom: 30, left: 40})
Insert cell
height = 400
Insert cell
Insert cell
x = d3.scalePoint()
.domain(monthList)
.range([margin.left, width - margin.right])
.padding(0.2)
Insert cell
y = d3.scaleLinear()
.domain([-10,20])
.range([height - margin.bottom, margin.top])
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
Insert cell
monthList = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]
Insert cell
function months(d) {
var mymonths = [];
for (const mon of monthList) {
mymonths.push({month: mon, value: +d[mon]})
}
return mymonths;
}
Insert cell
data[0]
Insert cell
data = d3.csv("https://gist.githubusercontent.com/simon-pinkmartini/ee766f1a22d4b8ccd707a5baf56ef98d/raw/4fe5eb759f07dee24e0972a529d489424143de29/meteoschweiz%252010.18751%2520v2.csv", d => ({
time: +d.time,
year: +d.year,
values: months(d)
})
)
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
import {button} from "@jashkenas/inputs"
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