79 lines
2.3 KiB
PHP
79 lines
2.3 KiB
PHP
<div class="cardDushant">
|
|
|
|
<?php
|
|
|
|
$GetYears = "SELECT DISTINCT YEAR(date) FROM health_index ORDER BY YEAR(date) asc";
|
|
$YearResult = mysqli_query($conn, $GetYears);
|
|
$YearArray = array();
|
|
while ($row = mysqli_fetch_array($YearResult)) {
|
|
array_push($YearArray, $row[0]);
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($YearArray)) {
|
|
|
|
foreach ($YearArray as $i) {
|
|
|
|
$sqlCheckUpForm = "SELECT score as health_index FROM health_index WHERE YEAR(date) = '" . $i . "' ";
|
|
error_log("Fetch Health Index YEAR " . $sqlCheckUpForm);
|
|
|
|
$resultCheckUpForm = mysqli_query($conn, $sqlCheckUpForm);
|
|
$firstChart = 0;
|
|
$secondChart = 0;
|
|
$thirdChart = 0;
|
|
$fourthChart = 0;
|
|
$fiveChart = 0;
|
|
$sixChart = 0;
|
|
|
|
while ($row = mysqli_fetch_array($resultCheckUpForm)) {
|
|
|
|
$healthIndexArrayAverageTrend[] = $row['health_index'];
|
|
}
|
|
// $month = date("F", mktime(0, 0, 0, $i, 10));
|
|
|
|
$sumHealthScoreTrend = array_sum($healthIndexArrayAverageTrend);
|
|
$countHealthScoreTrend = count($healthIndexArrayAverageTrend);
|
|
$averageTrend = round($sumHealthScoreTrend / $countHealthScoreTrend, 2);
|
|
$healthIndexTrend[$i] = ['firstChart' => $averageTrend ];
|
|
}
|
|
}
|
|
|
|
// echo ($firstChart + $secondChart + $thirdChart + $fourthChart + $fiveChart + $sixChart) / 6;
|
|
|
|
?>
|
|
|
|
<canvas id="healthIndexTrendChart" width="100%" height="70%"></canvas>
|
|
<?php
|
|
|
|
|
|
// Process trend data for Chart.js
|
|
$trendLabels = json_encode(array_keys($healthIndexTrend));
|
|
$trendfirstChart = json_encode(array_column($healthIndexTrend, 'firstChart'));
|
|
|
|
|
|
?>
|
|
|
|
<script>
|
|
var ctx = document.getElementById('healthIndexTrendChart').getContext('2d');
|
|
var healthIndexTrendChart = new Chart(ctx, {
|
|
type: 'line',
|
|
data: {
|
|
labels: <?php echo $trendLabels; ?>,
|
|
datasets: [{
|
|
label: 'Average health index',
|
|
data: <?php echo $trendfirstChart; ?>,
|
|
borderColor: '#ff0000',
|
|
fill: false
|
|
},
|
|
|
|
]
|
|
},
|
|
options: {
|
|
responsive: true
|
|
}
|
|
});
|
|
</script>
|
|
|
|
</div>
|