-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
97 lines (89 loc) · 2.42 KB
/
script.js
File metadata and controls
97 lines (89 loc) · 2.42 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
// 데이터를 API에서 가져오는 함수
async function fetchData(url) {
try {
const response = await fetch(url);
if (!response.ok) throw new Error("Failed to fetch data");
return await response.json();
} catch (error) {
console.error("Error fetching data:", error);
return null;
}
}
// 월간 위험 감지 차트
async function drawMonthlyRiskChart(email) {
const data = await fetchData(`/api/month-detected?email=${email}`);
if (!data) return;
// 데이터 처리
const labels = data.map((item) => item.detected_date);
const values = data.map((item) => item.daily_count);
const ctx = document.getElementById("monthlyRiskChart").getContext("2d");
new Chart(ctx, {
type: "line",
data: {
labels: labels,
datasets: [
{
label: "월간 위험 감지",
data: values,
borderColor: "#818cf8",
backgroundColor: "rgba(129, 140, 248, 0.2)",
borderWidth: 2,
pointRadius: 4,
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
ticks: { color: "#333" },
},
y: {
ticks: { color: "#333" },
beginAtZero: true,
},
},
},
});
}
// 유형별 민감 정보 차트
async function drawSensitiveInfoChart(email) {
const data = await fetchData(`/api/sensitive-info?email=${email}`);
if (!data) return;
// 데이터 처리
const labels = data.map((item) => item.content_type);
const values = data.map((item) => item.count);
const ctx = document.getElementById("sensitiveInfoChart").getContext("2d");
new Chart(ctx, {
type: "pie",
data: {
labels: labels,
datasets: [
{
data: values,
backgroundColor: ["#818cf8", "#f87171", "#fbbf24", "#34d399"],
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: "bottom",
labels: {
color: "#333",
font: { size: 12 },
},
},
},
},
});
}
// 페이지 로드 시 차트 생성
document.addEventListener("DOMContentLoaded", () => {
const email = "bblue6@naver.com"; // 테스트용 이메일
drawMonthlyRiskChart(email);
drawSensitiveInfoChart(email);
});