Covid All 50 US States Bar Graph(Excluding New York & New Jersey)


Table of Data

State Total Cases Total Deaths

Javascript Code


//MAKE GRAPH FUNCTION
function makegraph(labels,data, color){
    var ctx = document.getElementById('myChart');
    var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels:labels,
            datasets: [{
                label: '# of Cases',
                data: data,
                backgroundColor: color,
                borderColor: [
                    'rgba(0, 0, 255, 1)',
                    'rgba(54, 162, 235, 1)',
                    'rgba(255, 206, 86, 1)',
                    'rgba(75, 192, 192, 1)',
                    'rgba(153, 102, 255, 1)',
                    'rgba(255, 159, 64, 1)'
                ],
                borderWidth: 1
            }]
        },
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true
                    }
                }]
            }
        }
    });
}
//MAKE RANDOM COLORS FOR BAR GRAPH
var randomColorGenerator = function () { 
    return '#' + (Math.random().toString(16) + '0000000').slice(2, 8); 
};
//GET REQUEST OF COVID-19 data
//https://covid19-server.chrismichael.now.sh/api/v1/CasesInAllUSStates
$.get( "https://covid19-server.chrismichael.now.sh/api/v1/CasesInAllUSStates", function( data ) {
    
        var labels = [], dataarray=[]; color=[];
    
        //MAKE TABLES
        $.each(data.data[0].table, function (index, element) {
            //ADDS DATA TO THE TABLE
            if(element.USAState !== 'Total:' && element.USAState !== 'New Jersey' && element.USAState !== 'New York'){
                $( "#table" ).append('' + element.USAState + ''
                    + element.TotalCases +''
                    + element.TotalDeaths + '');
                //ARRAY PACKAGE DATA AND LABELS
                color.push(randomColorGenerator());
                labels.push(element.USAState);
                dataarray.push(element.TotalCases.replace(",", ""));
            }
        });
        //PUSH TO CHART FUNCTION DATA
        makegraph(labels,dataarray,color);
        //ADDS DATA JSON ON BOTTOM OF PAGE
        $( "body" ).append(JSON.stringify(data.data[0].table))
}, "json" );



Get Request JSON Data Dump