Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions pruebaTecnica_CesarFalla.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
//Intervalo de años que piden
$years = range(1995, 2020);
$values = [];

//Consumir la API y hacer un loop por cada año
foreach ($years as $year) {
$url = "https://api.worldbank.org/pip/v1/pip?country=PER&year=$year";
$json = file_get_contents($url);
$data = json_decode($json, true);

//En los años 1995 y 1996 no tienen datos por lo tanto validamos todos los headcounts
$values[] = $data[0]['headcount'] ?? null;

}
?>

<!DOCTYPE html>
<html>
<head>
<title>Gráfico de Pobreza en Perú</title>
<script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<div id="container" style="width:100%; height:400px;"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
var myChart = Highcharts.chart('container', {
chart: {
type: 'line'
},
title: {
text: 'Índice de Pobreza en Perú (1995-2020)'
},
xAxis: {
categories: <?php echo json_encode($years); ?>
},
yAxis: {
title: {
text: 'Headcount (%)'
}
},
series: [{
name: 'Pobreza',
data: <?php echo json_encode($values); ?>
}]
});
});
</script>
</body>
</html>