-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcategory.php
More file actions
157 lines (140 loc) · 6.13 KB
/
category.php
File metadata and controls
157 lines (140 loc) · 6.13 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Category</title>
<link rel="stylesheet" href="assets/navbar.css" type="text/css">
<link rel="stylesheet" href="category.css" type="text/css">
<!-- Google Font -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter&display=swap" rel="stylesheet">
<link rel=stylesheet href='category.php' type='text/css'>
<!-- Chart.js Script -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!-- Custom Script -->
<script src="category.js"></script>
<style>
.chart-container {
width: 400px;
height: 400px;
margin: auto;
}
</style>
</head>
<body style="
height: 1px; width: 1px;">
<span id="navbar">
<?php include 'navbar.php'; ?>
</span>
<div class="content">
<div class="title">
<p id="transaction_title">CATEGORY</p>
</div>
<br><br>
<div class="category_result">
<?php
session_start();
error_reporting(E_ALL);
ini_set("display_errors", 1);
include_once 'dbconfig.php';
$db_name = 'keeping';
mysqli_select_db($conn, $db_name);
$user_id = $_SESSION['username'];
$currentMonth = date('n'); // 현재 월을 기본값으로 설정
if (isset($_POST['currentMonth'])) {
$currentMonth = $_POST['currentMonth'];
$_SESSION['currentMonth'] = $currentMonth;
} elseif (isset($_SESSION['currentMonth'])) {
$currentMonth = $_SESSION['currentMonth'];
}
$categoryQuery = "SELECT c.category_name,
SUM(CASE
WHEN t.deposit_or_withdrawal = '+' THEN t.price
WHEN t.deposit_or_withdrawal = '-' THEN -t.price
ELSE 0
END) AS total_price
FROM transaction t
JOIN category c ON t.t_category_id = c.category_id
WHERE t.t_user_id = '$user_id' AND MONTH(t.date_t) = '$currentMonth'
GROUP BY c.category_name";
$result = $conn->query($categoryQuery);
$categories = array();
$prices = array();
if ($result && $result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$categories[] = $row['category_name'];
$prices[] = $row['total_price'];
}
}
?>
<form action="" method="post" class="monthForm" id="monthForm">
<span onclick="changeMonth(-1)">◀</span>
<span id="currentMonth"><?php echo $currentMonth; ?></span>월
<input type="hidden" name="currentMonth" id="hiddenCurrentMonth" value="<?php echo $currentMonth; ?>">
<span onclick="changeMonth(1)">▶</span>
<input type="submit" name="Check" value="Submit">
</form>
<br><br>
<div class="chart-container">
<canvas id="categoryPieChart"></canvas>
</div>
<script>
var ctx = document.getElementById('categoryPieChart').getContext('2d');
var categoryPieChart = new Chart(ctx, {
type: 'pie',
data: {
labels: <?php echo json_encode($categories); ?>,
datasets: [{
label: 'Category Prices',
data: <?php echo json_encode($prices); ?>,
backgroundColor: [
'rgba(255, 99, 132, 0.2)', // 붉은색
'rgba(54, 162, 235, 0.2)', // 파란색
'rgba(255, 206, 86, 0.2)', // 노란색
'rgba(75, 192, 192, 0.2)', // 청록색
'rgba(153, 102, 255, 0.2)', // 보라색
'rgba(255, 159, 64, 0.2)' // 주황색
],
borderColor: [
'rgba(255, 99, 132, 1)', // 붉은색
'rgba(54, 162, 235, 1)', // 파란색
'rgba(255, 206, 86, 1)', // 노란색
'rgba(75, 192, 192, 1)', // 청록색
'rgba(153, 102, 255, 1)', // 보라색
'rgba(255, 159, 64, 1)' // 주황색
],
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: true,
position: 'top',
labels: {
color: 'white', // 범례 글자 색상을 흰색으로 변경
font:{
family: 'Myanmar-Khyay',
size: 15
},
}
}
},
layout: {
padding: {
left: 10,
top: 10,
bottom: 10
}
}
}
});
</script>
</div>
</div>
</body>
</html>