Published
Edited
Mar 15, 2020
1 star
Insert cell
md`# Covid chart - confirmed cases`
Insert cell
md`Country confirmed ases based on JHU data https://github.com/CSSEGISandData/COVID-19`
Insert cell
countryindex = 100 //change to see other countries
Insert cell
{
const country_data = allcountrydata[100]
const country_data2 = allcountrydata[48]
const country_confirmed_data = country_data.confirmed
const country_confirmed_data2 = country_data2.confirmed
var confirmed = {
type: "scatter",
mode: "lines",
name: country_data.country,
x: unpackarray(country_confirmed_data, 0),
y: unpackarray(country_confirmed_data, 1),
line: {color: '#1700CF'}
}
var confirmed2 = {
type: "scatter",
mode: "lines",
name: country_data2.country,
x: unpackarray(country_confirmed_data2, 0),
y: unpackarray(country_confirmed_data2, 1),
line: {color: '#17BECF'}
}

var data = [confirmed, confirmed2];
var layout = {
title: countrydata.country + " & " + country_data2.country + " confirmed",
width: width,
legend: {
x: 0,
y: 1.0,
bgcolor: 'rgba(255, 255, 255, 0)',
bordercolor: 'rgba(255, 255, 255, 0)'
},
};
const div = DOM.element('div');
Plotly.newPlot(div, data, layout);
return div;
}
Insert cell
md`uses transformation from there https://github.com/covid19-data/covid19-data , 3 days old currently`
Insert cell
d3 = require("d3@^5.9")
Insert cell
datafile = "https://raw.githubusercontent.com/covid19-data/covid19-data/master/output/cntry_stat.json"
Insert cell
allcountrydata = d3.json(datafile)
Insert cell
countrydata = allcountrydata[countryindex]
Insert cell
{
const p = document.createElement("h1");
p.appendChild(document.createTextNode(countrydata.country));
return p;
}
Insert cell
myTable = {
const div = d3.select(html`<div></div<`);
const table = div.append("table");
const header = table.append("tr");
header.selectAll(".headerCell")
.data(["date", "confirmed", "deaths"])
.enter().append("td")
.attr("class", "headerCell")
.text(d => d);
const rows = table.selectAll(".row")
.data(countrydata.confirmed)
.enter().append("tr")
.attr("class", "row")
const cells = rows.selectAll(".cell")
.data(d => Object.values(d))
.enter().append("td")
.attr("class", "cell")
.text(d => d);
return div.node()
}
Insert cell
Plotly = require("https://cdn.plot.ly/plotly-latest.min.js")
Insert cell
async function csv(url) {
return Plotly.d3.csv.parse((await (await fetch(url)).text()));
}
Insert cell
function unpack(rows, key) {
return rows.map(function(row) {
return row[key];
});
}
Insert cell
function unpackarray(rows, i){
return rows.map(function(row){
return row[i]
});
}
Insert cell
countrydata.confirmed
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more