-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMonthlyResponse.html
More file actions
125 lines (111 loc) · 4.45 KB
/
MonthlyResponse.html
File metadata and controls
125 lines (111 loc) · 4.45 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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>보안 대시보드</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 30px;
}
.chart-container {
display: inline-block;
padding: 20px;
background: #fff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
max-width: 600px;
width: 100%;
margin: auto;
text-align: center;
}
.chart-title {
font-size: 1.5em;
margin-bottom: 10px;
font-weight: bold;
}
.total-count {
font-size: 1.8em;
font-weight: bold;
color: #333;
margin-bottom: 10px;
}
canvas {
max-width: 100%;
margin: auto;
}
</style>
</head>
<body>
<div class="chart-container">
<h3 class="chart-title">한 달간 감지된 민감 텍스트</h3>
<h1 id="totalCount" class="total-count">0건</h1>
<p>이번 달 총 감지 건수</p>
<canvas id="sensitiveChart"></canvas>
</div>
<script>
let chartInstance; // 차트 인스턴스 저장 변수
// ✅ API에서 데이터 가져와 차트 업데이트하는 함수
async function updateChart() {
try {
const response = await fetch('https://example.com/api/sensitive-data'); // ✅ 실제 API URL로 변경해야 함
if (!response.ok) throw new Error("API 요청 실패");
const data = await response.json();
// ✅ API에서 가져온 데이터 형식 예시
// data = [{ date: "03/01", detection_count: 12 }, { date: "03/02", detection_count: 7 }, ...]
const labels = data.map(item => item.date);
const values = data.map(item => item.detection_count);
const totalCount = values.reduce((acc, val) => acc + val, 0);
document.getElementById('totalCount').innerText = totalCount + '건';
if (!chartInstance) {
// ✅ 첫 차트 생성
const ctx = document.getElementById('sensitiveChart').getContext('2d');
chartInstance = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
data: values,
backgroundColor: 'rgba(104, 132, 245, 0.7)',
borderColor: 'rgba(104, 132, 245, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
legend: {
display: false // 범례 숨김
}
},
scales: {
x: { // ✅ X축 격자선 제거
grid: { display: false }
},
y: { // ✅ Y축 격자선 제거
grid: { display: false },
beginAtZero: true
}
}
}
});
} else {
// ✅ 기존 차트 데이터 업데이트
chartInstance.data.labels = labels;
chartInstance.data.datasets[0].data = values;
chartInstance.update();
}
} catch (error) {
console.error("데이터 로드 실패:", error);
document.getElementById('totalCount').innerText = "데이터 없음";
}
}
// ✅ 페이지 로드 시 차트 업데이트
updateChart();
// ✅ 5초마다 데이터 갱신
setInterval(updateChart, 5000);
</script>
</body>
</html>