Show sourcecode
The following files exists in this folder. Click to view.
public_html/smartkortet/pages/
hem.php
historik.php
installningar.php
restauranger.php
statistik.php
statistik.php
54 lines UTF-8 Windows (CRLF)
<?php
declare(strict_types=1);
require_once __DIR__ . '/../includes/data.php';
$userId = (int) $user['id'];
$selectedMonth = normalizeYearMonth($_GET['month'] ?? null);
[$year, $month] = array_map('intval', explode('-', $selectedMonth));
$daily = getDailySpendForMonth($userId, $year, $month);
$restaurants = getRestaurantDistributionForMonth($userId, $year, $month);
$lineLabels = array_column($daily, 'spent_on');
$lineValues = array_map('floatval', array_column($daily, 'total'));
$pieLabels = array_column($restaurants, 'label');
$pieValues = array_map('floatval', array_column($restaurants, 'total'));
?>
<article class="card panel">
<div class="row-between">
<h3>Statistik</h3>
<form method="get" class="inline-form">
<input type="hidden" name="tab" value="statistik">
<input type="month" name="month" value="<?= e($selectedMonth) ?>">
<button class="btn btn-secondary" type="submit">Visa</button>
</form>
</div>
<div class="chart-grid">
<section class="chart-card">
<h4>Utgifter över tid</h4>
<canvas id="line-chart"></canvas>
</section>
<section class="chart-card pie-card">
<h4>Fördelning per restaurang</h4>
<canvas id="pie-chart"></canvas>
</section>
</div>
</article>
<script>
window.MatkortetCharts = {
line: {
labels: <?= json_encode($lineLabels, JSON_UNESCAPED_UNICODE) ?>,
values: <?= json_encode($lineValues, JSON_UNESCAPED_UNICODE) ?>
},
pie: {
labels: <?= json_encode($pieLabels, JSON_UNESCAPED_UNICODE) ?>,
values: <?= json_encode($pieValues, JSON_UNESCAPED_UNICODE) ?>
}
};
</script>