Notebooks 2.0 is here.

Published
Edited
Oct 29, 2020
Insert cell
md`# Daily task week 3`
Insert cell
initDate = new Date("2014-01-01")
Insert cell
endDate = new Date("2017-01-01")
Insert cell
Insert cell
weather = weather_.filter(
d => d.date >= initDate && d.date <= endDate && d.location == "Seattle"
)
Insert cell
areachart = {
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height);

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

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

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

svg
.append("path")
.datum(weather)
.attr("fill", "none")
.attr("stroke", "purple")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round");
// .attr("d", line('cases'));

svg
.append("path")
.datum(weather)
.attr("fill", "none")
.attr("stroke", "purple")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", line);

svg
.append("path")
.datum(weather)
.attr("fill", 'steelblue')
.attr("d", area);

return svg.node();
}
Insert cell
area = d3.area()
.x(d => x(d.date))
.y0(d => y(d.temp_min))
.y1(d => y(d.temp_max))
Insert cell
line = d3.line()
.defined(d => !isNaN(d.date))
.x(d => x(d.date))
.y(d => y2(d.precipitation))
Insert cell
x = d3.scaleTime()
.domain(d3.extent(weather, d => d.date)).nice()
.range([margin.left, width - margin.right])

Insert cell
y = d3
.scaleLinear()
.domain([-10, d3.max(weather, d => d.temp_max)])
.nice()
.range([height - margin.bottom, margin.top])

Insert cell
y2 = d3
.scaleLinear()
.domain(d3.extent(weather, d => d.precipitation))
.nice()
.range([height - margin.bottom, margin.top])
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 60).tickSizeOuter(0))
Insert cell
yAxis = g =>
g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain"))
.call(g =>
g
.select(".tick:last-of-type text")
.clone()
.attr("x", 3)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text("Temperature")
)
Insert cell
yAxis2 = g =>
g
.attr("transform", `translate(${width - margin.right},0)`)
.call(d3.axisRight(y2))
.call(g => g.select(".domain"))
.call(g =>
g
.select(".tick:last-of-type text")
.clone()
.attr("x", -3)
.attr("text-anchor", "end")
.attr("font-weight", "bold")
.text("Precipitation")
)
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