-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
131 lines (119 loc) · 5.36 KB
/
index.html
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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>QBハウスxxx店の待ち人数推移</title>
<!-- Google Chartsのロード -->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
google.charts.load('current', { 'packages': ['corechart'] });
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var selectedDate = document.getElementById("dateDropdown").value;
// 選択された日付を使用して処理を行う
console.log("選択された日付: " + selectedDate);
// ここに選択された日付に対する処理を追加
// AJAXリクエスト
$.ajax({
url: `https://busy-qbhouse.khayama.workers.dev?date=${selectedDate}`,
method: 'GET',
dataType: 'json',
success: function (json) {
const array = json.map(elm => {
return [[parseInt(elm.hour), parseInt(elm.min), parseInt("00")], parseInt(elm.num)]
})
//console.log(`array === ${array}`)
var data = new google.visualization.DataTable();
data.addColumn('timeofday', '時間');
data.addColumn('number', '待ち人数');
data.addRows(array);
var options = {
title: 'QBハウスxxx店の待ち人数推移',
width: 800,
height: 400,
hAxis: {
title: '時間',
format: 'HH:mm', // 24時間表記
viewWindow: {
min: [9, 0, 0], // 横軸の最小値 (09:00)
max: [20, 0, 0] // 横軸の最大値 (20:00)
},
},
vAxis: {
title: '待ち人数',
minValue: 0, // 縦軸の最小値
maxValue: 10 // 縦軸の最大値
},
colors: ['blue'], // 線の色 (洒落た感じに調整可能)
legend: 'none'
};
var chart = new google.visualization.LineChart(document.getElementById('lineChart'));
chart.draw(data, options);
},
error: function (error) {
console.error('データの取得に失敗しました:', error);
}
});
}
function padTwoDigits(num) {
return num.toString().padStart(2, "0");
}
function dateInYyyyMmDdHhMmSs(date, dateDiveder = "-") {
// :::: Exmple Usage ::::
// The function takes a Date object as a parameter and formats the date as YYYY-MM-DD hh:mm:ss.
// 👇️ 2023-04-11 16:21:23 (yyyy-mm-dd hh:mm:ss)
//console.log(dateInYyyyMmDdHhMmSs(new Date()));
// 👇️️ 2025-05-04 05:24:07 (yyyy-mm-dd hh:mm:ss)
// console.log(dateInYyyyMmDdHhMmSs(new Date('May 04, 2025 05:24:07')));
// Date divider
// 👇️ 01/04/2023 10:20:07 (MM/DD/YYYY hh:mm:ss)
// console.log(dateInYyyyMmDdHhMmSs(new Date(), "/"));
return (
[
date.getFullYear(),
padTwoDigits(date.getMonth() + 1),
padTwoDigits(date.getDate()),
].join(dateDiveder) +
" " +
[
padTwoDigits(date.getHours()),
padTwoDigits(date.getMinutes()),
'00',
].join(":")
);
}
// ドロップダウンリストに日付を動的に追加する関数
function populateDateDropdown() {
var dropdown = document.getElementById("dateDropdown");
var currentDate = new Date(Date.now() + ((new Date().getTimezoneOffset() + (9 * 60)) * 60 * 1000));
for (var i = 0; i < 14; i++) {
var date = new Date(currentDate);;
console.log(`JST Date === ${dateInYyyyMmDdHhMmSs(currentDate)}`)
date.setDate(currentDate.getDate() - i);
var formattedDate = dateInYyyyMmDdHhMmSs(date).slice(0, 10); // YYYY-MM-DD 形式に変換
var option = document.createElement("option");
option.value = formattedDate;
option.textContent = formattedDate;
dropdown.appendChild(option);
}
}
// ページ読み込み時にドロップダウンリストを生成
window.onload = function () {
populateDateDropdown();
};
</script>
</head>
<body>
<div style="text-align: center;">
<h1>QBハウスxxx店の待ち人数推移</h1>
</div>
<div style="text-align: center;">
<h4>日付を選択</h4>
<select id="dateDropdown" onchange="drawChart()"></select>
</div>
<div style="width: 700px; margin: 0 auto;">
<div id="lineChart"></div>
</div>
</body>
</html>