Get the corona cases in your country

3 weeks ago

mpociot

Data taken from: https://github.com/ExpDev07/coronavirus-tracker-api

Controller:

// Change this for your specific country
$countryCode = 'DE';

$confirmed = Http::get('https://coronavirus-tracker-api.herokuapp.com/confirmed')->json();
$confirmedData = collect($confirmed['locations'])->where('country_code', $countryCode)->first();

$chartData = [
	['Date', '# Confirmed']
];

collect($confirmedData['history'])->sortBy(function ($numConfirmed, $date) {
	return Carbon\Carbon::createFromFormat('n/j/y', $date)->startOfDay();
})->map(function ($numConfirmed, $date) use (&$chartData) {
  $chartData[] = [$date, $numConfirmed];
});

return view('__tinker__::tinker', [
  	'chartData' => $chartData,
	'country' => $confirmedData['country']
]);

View:

<body>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
      <script type="text/javascript">
        google.charts.load('current', {'packages': ['corechart']});
        google.charts.setOnLoadCallback(drawChart);
        function drawChart() {
            var data = google.visualization.arrayToDataTable(@json($chartData));
            var chart = new google.visualization.AreaChart(document.getElementById('chart'));
            chart.draw(data, {
                title: 'Corona cases in {{ $country }}',
                legend: {position: 'bottom'},
                width: '100%',
                height: '900'
            });
        }
    </script>
	<div style="height:100%;width:100%;" id="chart"></div>
</body>