xxxxxxxxxx
var APIURL = 'https://data.cityofnewyork.us/resource/xwtc-hedq.json';
var thestuff = {};
var isready = false;
var Yarray1 = []; //confirmed cases
var Yarray2 = []; //probable cases
var Yarray3 = []; //total cases
var Xarray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]; //number of days since start date of data collection
let numPts = 25;
function preload() {
thestuff = loadJSON(APIURL, goforit);
}
function setup() {
createCanvas(500,1100);
if(isready)
{
for(let i =0;i<numPts;i++)
{
Yarray1.push(1100-(thestuff[i].confirmed_cases));
Yarray2.push(1100-(thestuff[i].probable_cases));
Yarray3.push(1100-(thestuff[i].total_cases));
}
}
// console.log(Yarray1);
//console.log(Yarray2);
//console.log(Yarray3);
// console.log(Xarray);
}
function draw() {
background(220);
textSize(30);
fill(0);
text('NYC COVID-19 Cases over Time', 10, 30);
textSize(25);
text('2020 Sep 30 - 2020 Oct 30', 10, 60);
fill('green');
textSize(15);
text('confirmed cases', 10, 80);
fill('blue');
text('probable cases', 10, 100);
fill('red');
text('total cases', 10, 120);
drawLines();
drawEllipses();
}
function drawEllipses(){
noStroke();
fill('green');
for(let i =0; i < Yarray1.length; i++){
let x = i * (width / (numPts-1));
let y = Yarray1[i];
ellipse(x, y, 7);
}
fill('blue');
for(let i =0; i < Yarray2.length; i++){
let x = i * (width / (numPts-1));
let y = Yarray2[i];
ellipse(x, y, 7);
}
fill('red');
for(let i =0; i < Yarray3.length; i++){
let x = i * (width / (numPts-1));
let y = Yarray3[i];
ellipse(x, y, 7);
}
}
function drawLines(){
stroke('DarkGreen');
var px = 0;
let py1 = Yarray1[0];
for(let i =0; i < Yarray1.length; i++){
let x = i * (width / (numPts-1));
let y = Yarray1[i];
line(px, py1, x, y);
px = x;
py1 = y;
}
stroke('DarkBlue');
px=0;
let py2 = Yarray2[0];
for(let i =0; i < Yarray2.length; i++){
let x = i * (width / (numPts-1));
let y = Yarray2[i];
line(px, py2, x, y);
//store the last position
px = x;
py2 = y;
}
stroke('DarkRed');
px=0
let py3 = Yarray3[0];
for(let i =0; i < Yarray3.length; i++){
let x = i * (width / (numPts-1));
let y = Yarray3[i];
line(px, py3, x, y);
px = x;
py3 = y;
}
}
function goforit() {
isready = true;
//console.log(thestuff);
}