Published
Edited
Apr 21, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
course = "HIST 390" // A string
Insert cell
year = 2021 // A number
Insert cell
message = `Hello, ${course} students from ${year}` // Another string, which uses earlier variables
Insert cell
courseObject = ({
title: "The Digital Past",
catalog: "HIST 390",
instructor: "Lincoln Mullen",
students: ["A", "B", "C", "D", "E"] // An array of students
})
Insert cell
courseObject.catalog
Insert cell
`${courseObject.title} (${courseObject.catalog})`
Insert cell
Insert cell
bookPrices = [12.40, 19.99, 15.00, 45.00, 9.00]
Insert cell
function sum(x) {
let total = 0;
for (let i = 0; i < x.length; i++) {
total += x[i];
}
return total;
}
Insert cell
sum(bookPrices)
Insert cell
function average(x) {
return sum(x) / x.length;
}
Insert cell
average(bookPrices)
Insert cell
Insert cell
function geocode(address, city, state, zip) {
let place = encodeURI(`${address}, ${city}, ${state} ${zip}`);
// let url = `https://geocoding.geo.census.gov/geocoder/locations/onelineaddress?address=${place}&benchmark=2020&format=json`;
let url = `https://geocode.xyz/${place}?json=1&auth=408344306725209919059x89261`;
let response = d3.json(url);
return response;
}
Insert cell
location = geocode("3211 Providence Drive", "Anchorage", "AK", "99508")
Insert cell
gmuLocation = FileAttachment("location.json").json()
Insert cell
function getStation(location) {
let lat = location.latt;
let lon = location.longt;
let station = d3.json(`https://api.weather.gov/points/${lat},${lon}`);
return station;
}
Insert cell
station = getStation(gmuLocation)
Insert cell
gmuStation = FileAttachment("station.json").json()
Insert cell
getForecast = function(station) {
let forecast = d3.json(station.properties.forecast);
return forecast;
}
Insert cell
forecast = getForecast(gmuStation)
Insert cell
gmuForecast = FileAttachment("forecast.json").json()
Insert cell
d3.json("https://api.weather.gov/gridpoints/OKX/33,37/forecast")
Insert cell
gmuForecast.properties.periods[0]
Insert cell
md`### Weather in ${gmuLocation.standard.city}`
Insert cell
weatherChart
Insert cell
md`## Imports`
Insert cell
d3 = require("d3@v6")
Insert cell
import { weatherChart } from "@kerryrodden/simple-custom-weather-chart-in-d3"
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