-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresults.php
More file actions
39 lines (36 loc) · 892 Bytes
/
results.php
File metadata and controls
39 lines (36 loc) · 892 Bytes
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
<?php
include 'db.php';
$data = [];
$sql = "SELECT topic, AVG(score) as avg_score FROM results GROUP BY topic";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Analytics</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<h2>Average Score per Topic</h2>
<canvas id="analyticsChart" width="500" height="300"></canvas>
<script>
const data = <?php echo json_encode($data); ?>;
const labels = data.map(d => d.topic);
const scores = data.map(d => parseFloat(d.avg_score));
new Chart(document.getElementById("analyticsChart"), {
type: "bar",
data: {
labels: labels,
datasets: [{
label: "Avg Score",
data: scores,
backgroundColor: "#2196f3"
}]
}
});
</script>
</body>
</html>