Published
Edited
Feb 27, 2020
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
headers = ({
'X-App-Token': token
})
Insert cell
Insert cell
d3.json(endpoint + '?$limit=1', {'method': 'GET', 'headers': headers})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
range = {
const today = new Date();
const year = today.getFullYear();
const thisMonth = today.getMonth();
const lastMonth = (thisMonth - 1) % 12;
// figure out first and last dates of last month
const lastStart = new Date(year, lastMonth, 1);
const thisStart = new Date(year, thisMonth, 1);
const lastEnd = new Date(thisStart.setDate(thisStart.getDate() - 1));
// format should be: 2019-05-01T01:00:00.000
const dateFormat = d3.timeFormat("%Y-%m-%dT%H:%M:%S.%L")
return {
start: dateFormat(lastStart),
end: dateFormat(lastEnd)
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
encoded = new URLSearchParams(parameters).toString()
Insert cell
Insert cell
json = d3.json(`${endpoint}?${encoded}`, {'method': 'GET', 'headers': headers})
Insert cell
Insert cell
json[0]
Insert cell
json.slice(-1)[0]
Insert cell
Insert cell
incidents = {
const dateParse = d3.timeParse("%Y-%m-%dT%H:%M:%S.%L");
return json.map(function(row) {
return {
date: dateParse(row.incident_date),
district: row.police_district,
count: parseInt(row.count_distinct_incident_number)
}
})
}
Insert cell
incidents[0]
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