-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart.php
79 lines (68 loc) · 1.87 KB
/
chart.php
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
require __DIR__ .'/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpClient\HttpClient;
// Ottengo la Request dal Web
$request = Request::createFromGlobals();
// Parametri passati in GET
$istat = $request->query->get('istat','082053');
$height = $request->query->get('height','400');
$width = $request->query->get('width','200');
$sizeTitle = $request->query->get('size-title','20');
// Chiamo API del progetto COVID OPEN REPORT
$url = "https://covid-open-report-sicilia.herokuapp.com/vaccini/latest?q=".$istat;
$client = HttpClient::create();
$response = $client->request(
'GET',
$url
);
$statusCode = $response->getStatusCode();
if ($statusCode == 200) {
$content = $response->toArray()[0];
$comune = $content['comune'];
$vaccinati = $content['seconda_dose'];
$dataPieces = explode("-", $content['data']);
$data = $dataPieces[2]."/".$dataPieces[1]."/".$dataPieces[0];
} else {
print("Error");
}
// Configuro il grafico con QuickChart
$config = <<<START
{
type: 'radialGauge',
data: {
datasets: [{
data: [$vaccinati],
backgroundColor: getGradientFillHelper('horizontal', ['green', 'green']),
label: '% Vaccinati',
}]
},
options: {
domain: [0, 100],
trackColor: '#f0f8ff',
centerPercentage: 70,
centerArea: {
displayText: true,
text: (val) => val + '%',
subText:'$data',
},
title: {
text: 'Vaccinati 2° Dose $comune',
display: true,
fontSize: $sizeTitle,
},
}
}
START;
$qc = new QuickChart(array(
'width'=> $width,
'height'=> $height,
//'protocol'=>'',
//'host'=>'',
//'port'=>''
));
$qc->setConfig($config);
$image = $qc->toBinary();
// OUTPUT IMMAGINE
header('Content-Type: image/png');
print($image);