Public
Edited
Mar 17, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// get the data based on the year selection
dataPerYear = fetch(`https://ergast.com/api/f1/${year}/status.json`).then((response) => response.json()).then((el) => el.MRData.StatusTable.Status)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataPerYear
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
allYearsStatus = {
return await Promise.all(
yearsArr.map(async (year) => {
const response = await fetch(`https://ergast.com/api/f1/${year}/status.json`);
const data = await response.json();
return {
year: year,
collision: parseInt(data.MRData.StatusTable.Status.filter(el => el.status === "Collision").map(el => el.count).join()),
accident: parseInt(data.MRData.StatusTable.Status.filter(el => el.status === "Accident").map(el => el.count).join())
};
}))
}
Insert cell
allYearsStatus
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
viewof statSel = Inputs.select(["collision", "accident"], {label: "Select stat"})
Insert cell
Plot.plot({
marks: [
Plot.barY(allYearsStatus, {x: "year", y: statSel, fill: "year"}),
Plot.ruleY([0])
]
})
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