-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph_Appointements.php
77 lines (67 loc) · 2.29 KB
/
Graph_Appointements.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
<?php
require('connection.php');
require('header.php');
// Fetch the statistics data
$stmt = $conn->prepare("SELECT typeSoin.nomSoin, COUNT(appointments.id_appointment) AS appointmentCount
FROM typeSoin
LEFT JOIN appointments ON typeSoin.id_typeSoin = appointments.id_typeSoin
GROUP BY typeSoin.nomSoin");
$stmt->execute();
$statistics = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Prepare the data for the graph
$labels = [];
$data = [];
$backgroundColor = [];
$borderColor = [];
foreach ($statistics as $row) {
$labels[] = $row['nomSoin'];
$data[] = $row['appointmentCount'];
// Generate random colors
$backgroundColor[] = 'rgba(' . rand(0, 255) . ',' . rand(0, 255) . ',' . rand(0, 255) . ', 0.5)';
$borderColor[] = 'rgba(' . rand(0, 255) . ',' . rand(0, 255) . ',' . rand(0, 255) . ', 1)';
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Appointment Graph</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<div class="container">
<h2 class="text-center mt-5">Appointment Graph</h2>
<canvas id="appointmentsChart"></canvas>
</div>
<script>
// Get the data from PHP
var labels = <?php echo json_encode($labels); ?>;
var data = <?php echo json_encode($data); ?>;
var backgroundColor = <?php echo json_encode($backgroundColor); ?>;
var borderColor = <?php echo json_encode($borderColor); ?>;
// Create the chart
var ctx = document.getElementById('appointmentsChart').getContext('2d');
var chart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Appointment Count',
data: data,
backgroundColor: backgroundColor,
borderColor: borderColor,
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true,
precision: 0
}
}
}
});
</script>
</body>
</html>