Published
Edited
Apr 13, 2020
Insert cell
Insert cell
viewof line = vl.markLine()
.width(750)
.height(400)
.data(all)
.encode(
vl.x().fieldQ("index").axis({ title: 'Days since Countries Patient Zero' }),
vl.y().fieldQ("Cases").axis({ title: 'Deaths' }),
vl.color().fieldN("Country")
)
.render()
Insert cell
liveDataUK = (await fetch("https://api.covid19api.com/total/dayone/country/united-kingdom/status/deaths")).json();
Insert cell
liveDataItaly = (await fetch("https://api.covid19api.com/total/dayone/country/italy/status/deaths")).json();
Insert cell
liveDataSpain = (await fetch("https://api.covid19api.com/total/dayone/country/spain/status/deaths")).json();

Insert cell
liveDataChina = (await fetch("https://api.covid19api.com/total/dayone/country/china/status/deaths")).json();

Insert cell
liveDataUsa = (await fetch("https://api.covid19api.com/total/dayone/country/us/status/deaths")).json();

Insert cell
Insert cell
liveDataItalyIndexed = (() => {
let x = 1;
liveDataItaly.map((item) => {item.index = x; x++; return item;})
return liveDataItaly;
})();
Insert cell
liveDataChinaIndexed = (() => {
let x = 1;
liveDataChina.map((item) => {item.index = x; x++; return item;})
return liveDataChina;
})();
Insert cell
liveDataSpainIndexed = (() => {
let x = 1;
liveDataSpain.map((item) => {item.index = x; x++; return item;})
return liveDataSpain;
})();
Insert cell
liveDataUKIndexed = (() => {
let x = 1;
liveDataUK.map((item) => {item.index = x; x++; return item;})
return liveDataUK;
})();
Insert cell
liveDataUsaIndexed = (() => {
let x = 1;
liveDataUsa.map((item) => {item.index = x; x++; return item;})
return liveDataUsa;
})();
Insert cell
all = (liveDataUKIndexed.concat(liveDataSpainIndexed, liveDataUsaIndexed, liveDataItalyIndexed, liveDataChina)).sort((a, b) => new Date(a.Date) - new Date(b.Date))
Insert cell
import {vl} from '@vega/vega-lite-api';


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