Published
Edited
Jul 22, 2020
1 fork
Also listed in…
Season 1
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// This will call the fetchData function for each signal in the list and return an array with all the data in the same order
dataList = Promise.all(
signals.map(async signal => {
const d = await fetchData(signal.signal, date, fips);
d.signal = signal.signal
d.source = signal.source
return d;
})
)
Insert cell
data = {
let obj = {};
dataList.forEach((d, i) => {
obj[d.signal] = d;
});
return obj;
}
Insert cell
Insert cell
md`## Visualize metric for a county over time`
Insert cell
renderLine(signals[0].signal)
Insert cell
renderLine(signals[1].signal)
Insert cell
renderLine(signals[2].signal)
Insert cell
renderLine(signals[3].signal)
Insert cell
renderLine(signals[4].signal)
Insert cell
function renderLine(signal) {
return (
vl
.markLine()
.data(
data[signal].epidata.map(d => {
let s = "" + d.time_value;
return {
time_value: new Date(
`${s.slice(0, 4)}-${s.slice(4, 6)}-${s.slice(6, 8)} 12:01`
),
value: d.value
};
})
)
.view({
height: 40
})
.encode(
vl.x().fieldT("time_value"), // date parsing!
vl.y().fieldQ("value")
)
.title(signalMap[signal].label)
//.config({ title: 'hi'})
.render()
);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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