28
loading...
This website collects cookies to deliver better user experience
url = 'https://data.cdc.gov/resource/k8wy-p9cg.json?state=CA'
require
d3-fetch
in order to have access to its JSON parser method to use with the CDC API.d3Fetch = require('d3-fetch')
d3-fetch
object we can now fetch and parse through our JSON data.covidData = d3.json(url)
changedData = {
let parsedData = [];
for (let i = 0; i < covidData.length; i++) {
let data = covidData[i];
data['hispanic'] = data['hispanic'] * 100;
parsedData.push(data);
}
return parsedData;
}
for
loop, I change the value for hispanic from the original decimal value to a more usable number for my graph.require
Vega Lite like so:vegalite = require('@observablehq/vega-lite')
vegalite({
data: { values: changedData },
mark: {
type: "area",
line: {
color: "darkgreen"
},
color: {
x1: 1,
y1: 1,
x2: 1,
y2: 0,
gradient: "linear",
stops: [
{
offset: 0,
color: "white"
},
{
offset: 1,
color: "darkgreen"
}
]
}
},
autosize: "fit",
width: width,
encoding: {
x: {
field: "county_name",
type: "ordinal"
},
y: {
field: "hispanic",
type: "quantitative"
}
}
})