質問編集履歴
4
うううううううううう
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
ああああああああああ
|
test
CHANGED
@@ -1,345 +1,5 @@
|
|
1
|
-
|
1
|
+
ああああああああああ
|
2
2
|
|
3
|
-
|
3
|
+
ああああああああああ
|
4
4
|
|
5
|
-
データはMySQLに格納されており、PHPで取得、画面からはJavaScript(Ajax)でデータのやり取りている。
|
6
|
-
|
7
|
-
返り値はJSON。
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
### 発生している問題・エラーメッセージ
|
12
|
-
|
13
|
-
submitしてもグラフが表示されない。
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
### 該当のソースコード
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
```PHP
|
22
|
-
|
23
|
-
<?php
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
//エラーメッセージ初期化
|
28
|
-
|
29
|
-
$errorMessage = "";
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
$s_year = filter_input(INPUT_GET, 's_year');
|
34
|
-
|
35
|
-
$s_month = filter_input(INPUT_GET, 's_month');
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if (empty($s_year)) {
|
40
|
-
|
41
|
-
$s_year = date('Y');
|
42
|
-
|
43
|
-
$s_month = date('n') - 1;
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
// セッション開始
|
50
|
-
|
51
|
-
session_start();
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
$db['host'] = "localhost"; // DBサーバのURL
|
56
|
-
|
57
|
-
$db['user'] = "amamiya"; // ユーザー名
|
58
|
-
|
59
|
-
$db['pass'] = "nishizono"; // ユーザー名のパスワード
|
60
|
-
|
61
|
-
$db['dbname'] = "eyebank"; // データベース名
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
$dsn = sprintf('mysql: host=%s; dbname=%s; charset=utf8', $db['host'], $db['dbname']);
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
//SQL実行
|
70
|
-
|
71
|
-
try {
|
72
|
-
|
73
|
-
$pdo = new PDO($dsn, $db['user'], $db['pass'], array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
//データ取得
|
78
|
-
|
79
|
-
$sql = 'select * from s_time where s_year = ' . $s_year . ' and s_month = ' . $s_month . ' order by s_year, s_month, s_date';
|
80
|
-
|
81
|
-
$stmt = $pdo->prepare($sql);
|
82
|
-
|
83
|
-
$stmt->execute();
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
} catch (PDOException $e) {
|
88
|
-
|
89
|
-
$errorMessage = $errorMessage.'データベースエラー';
|
90
|
-
|
91
|
-
$errorMessage = $errorMessage.$sql;
|
92
|
-
|
93
|
-
echo $e->getMessage();
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
$s_date = '';
|
100
|
-
|
101
|
-
$s_time = '';
|
102
|
-
|
103
|
-
$temp_s_time = '';
|
104
|
-
|
105
|
-
$backgroundcolor = '';
|
106
|
-
|
107
|
-
$bordercolor = '';
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
//loop through the returned data
|
112
|
-
|
113
|
-
while( $r = $stmt->fetch(PDO::FETCH_ASSOC)){
|
114
|
-
|
115
|
-
$s_date = $s_date . '"'. $r['s_date'].'",';
|
116
|
-
|
117
|
-
$s_time = $s_time . '"'. $r['s_time'] .'",';
|
118
|
-
|
119
|
-
$temp_s_time = $r['s_time'];
|
120
|
-
|
121
|
-
if ($temp_s_time >= 11.5) {
|
122
|
-
|
123
|
-
$backgroundcolor = $backgroundcolor . "'rgba(255, 159, 64, 0.2)'" . ', ';
|
124
|
-
|
125
|
-
$bordercolor = $bordercolor . "'rgba(255, 159, 64, 1)'" . ', ';
|
126
|
-
|
127
|
-
}else{
|
128
|
-
|
129
|
-
$backgroundcolor = $backgroundcolor . "'rgba(54, 162, 235, 0.2)'" . ', ';
|
130
|
-
|
131
|
-
$bordercolor = $bordercolor . "'rgba(54, 162, 235, 1)'" . ', ';
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
$s_date = trim($s_date,",");
|
140
|
-
|
141
|
-
$s_time = trim($s_time,",");
|
142
|
-
|
143
|
-
$backgroundcolor = trim($backgroundcolor,",");
|
144
|
-
|
145
|
-
$bordercolor = trim($bordercolor,",");
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
$array = [$s_date, $s_time, $backgroundcolor, $bordercolor];
|
150
|
-
|
151
|
-
$json = json_encode( $array );
|
152
|
-
|
153
|
-
echo $json;
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
?>
|
158
|
-
|
159
|
-
```
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
```HTML
|
164
|
-
|
165
|
-
<!DOCTYPE html>
|
166
|
-
|
167
|
-
<html lang="ja">
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
<head>
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
<meta charset="UTF-8">
|
176
|
-
|
177
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
178
|
-
|
179
|
-
<meta name="robots" content="noindex" />
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
<title>s-system</title>
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
<link rel="stylesheet" type="text/css" href="css/s_system.css">
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
</head>
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
<body>
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
<div class="stripe-pattern">
|
204
|
-
|
205
|
-
<h1>s-system</h1>
|
206
|
-
|
207
|
-
</div>
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
<br><br>
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
<script>
|
216
|
-
|
217
|
-
function OnButtonClick(){
|
218
|
-
|
219
|
-
$s_year = document.getElementById("s_year").value;
|
220
|
-
|
221
|
-
$s_month = document.getElementById("s_month").value;
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
$.ajax({
|
226
|
-
|
227
|
-
type: "POST",
|
228
|
-
|
229
|
-
url: "s_time.php",
|
230
|
-
|
231
|
-
data: {"s_year": $s_year, "s_month": $s_month},
|
232
|
-
|
233
|
-
dataType : "json",
|
234
|
-
|
235
|
-
success: function(result){
|
236
|
-
|
237
|
-
}.done(function(data){
|
238
|
-
|
239
|
-
var json = JSON.parse(data);
|
240
|
-
|
241
|
-
alert(json[0]);
|
242
|
-
|
243
|
-
})
|
244
|
-
|
245
|
-
})
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
}
|
250
|
-
|
251
|
-
</script>
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
<script>
|
256
|
-
|
257
|
-
var year = today.getFullYear();
|
258
|
-
|
259
|
-
var s_year = document.getElementById("s_year");
|
260
|
-
|
261
|
-
s_year.value = year;
|
262
|
-
|
263
|
-
</script>
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
<input type="text" id="s_year" value="">年<input type="text" id="s_month" value="">月
|
268
|
-
|
269
|
-
<input type="button" value="抽出" onclick="OnButtonClick();">
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
<canvas id="sTime" width="400" height="400"></canvas>
|
274
|
-
|
275
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
|
276
|
-
|
277
|
-
<script>
|
278
|
-
|
279
|
-
var ctx = document.getElementById('sTime').getContext('2d');
|
280
|
-
|
281
|
-
var myChart = new Chart(ctx, {
|
282
|
-
|
283
|
-
type: 'bar',
|
284
|
-
|
285
|
-
data: {
|
286
|
-
|
287
|
-
labels: [json[0]],
|
288
|
-
|
289
|
-
datasets: [{
|
290
|
-
|
291
|
-
label: 'S時間',
|
292
|
-
|
293
|
-
data: [json[1]],
|
294
|
-
|
295
|
-
backgroundColor: [json[3]],
|
296
|
-
|
297
|
-
borderColor: [json[4]],
|
298
|
-
|
299
|
-
borderWidth: 1
|
300
|
-
|
301
|
-
},
|
302
|
-
|
303
|
-
]
|
304
|
-
|
305
|
-
},
|
306
|
-
|
307
|
-
|
5
|
+
ああああああああああ
|
308
|
-
|
309
|
-
scales: {
|
310
|
-
|
311
|
-
yAxes: [{
|
312
|
-
|
313
|
-
ticks: {
|
314
|
-
|
315
|
-
beginAtZero: true
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
}]
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
});
|
326
|
-
|
327
|
-
</script>
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
</body>
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
</html>
|
336
|
-
|
337
|
-
```
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
### 試したこと
|
342
|
-
|
343
|
-
PHPをHTMLと同じファイル内に書き、フォームオープン時に実行されることは確認しました。
|
344
|
-
|
345
|
-
また、Ajaxでsuccessを通るのは確認できました。
|
3
test
CHANGED
File without changes
|
test
CHANGED
@@ -256,7 +256,7 @@
|
|
256
256
|
|
257
257
|
var year = today.getFullYear();
|
258
258
|
|
259
|
-
var s
|
259
|
+
var s_year = document.getElementById("s_year");
|
260
260
|
|
261
261
|
s_year.value = year;
|
262
262
|
|
@@ -270,13 +270,13 @@
|
|
270
270
|
|
271
271
|
|
272
272
|
|
273
|
-
<canvas id="s
|
273
|
+
<canvas id="sTime" width="400" height="400"></canvas>
|
274
274
|
|
275
275
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
|
276
276
|
|
277
277
|
<script>
|
278
278
|
|
279
|
-
var ctx = document.getElementById('s
|
279
|
+
var ctx = document.getElementById('sTime').getContext('2d');
|
280
280
|
|
281
281
|
var myChart = new Chart(ctx, {
|
282
282
|
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -156,6 +156,8 @@
|
|
156
156
|
|
157
157
|
?>
|
158
158
|
|
159
|
+
```
|
160
|
+
|
159
161
|
|
160
162
|
|
161
163
|
```HTML
|
@@ -332,6 +334,8 @@
|
|
332
334
|
|
333
335
|
</html>
|
334
336
|
|
337
|
+
```
|
338
|
+
|
335
339
|
|
336
340
|
|
337
341
|
### 試したこと
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,10 +20,6 @@
|
|
20
20
|
|
21
21
|
```PHP
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
PHP
|
26
|
-
|
27
23
|
<?php
|
28
24
|
|
29
25
|
|
@@ -118,7 +114,7 @@
|
|
118
114
|
|
119
115
|
$s_date = $s_date . '"'. $r['s_date'].'",';
|
120
116
|
|
121
|
-
$s_time = $s
|
117
|
+
$s_time = $s_time . '"'. $r['s_time'] .'",';
|
122
118
|
|
123
119
|
$temp_s_time = $r['s_time'];
|
124
120
|
|
@@ -162,11 +158,7 @@
|
|
162
158
|
|
163
159
|
|
164
160
|
|
165
|
-
```HTML(JavaScript)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
HTML
|
161
|
+
```HTML
|
170
162
|
|
171
163
|
<!DOCTYPE html>
|
172
164
|
|