質問編集履歴
1
ソース追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,349 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
|
19
|
+
```html
|
20
|
+
|
21
|
+
<!doctype html>
|
22
|
+
|
23
|
+
<html>
|
24
|
+
|
25
|
+
<head>
|
26
|
+
|
27
|
+
<meta charset="utf-8" content="">
|
28
|
+
|
29
|
+
<title>google-chart</title>
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type="text/javascript" ></script>
|
34
|
+
|
35
|
+
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
36
|
+
|
37
|
+
<script src="../jRange/jquery.range.js"></script>
|
38
|
+
|
39
|
+
<link rel="stylesheet" href="../jRange/jquery.range.css">
|
40
|
+
|
41
|
+
<!-- スクリプト部分 -->
|
42
|
+
|
43
|
+
<script type="text/javascript" src="../js/graph.js"></script>
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
</head>
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
<!-- HTML部分 -->
|
52
|
+
|
53
|
+
<body>
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
<h1></h1>
|
58
|
+
|
59
|
+
</div>
|
60
|
+
|
61
|
+
<div id="dashboard_div" style="text-align: center;">
|
62
|
+
|
63
|
+
<!--Divs that will hold each control and chart-->
|
64
|
+
|
65
|
+
<div id="chart_div"></div>
|
66
|
+
|
67
|
+
<table width=800px style="display: none;">
|
68
|
+
|
69
|
+
<tr>
|
70
|
+
|
71
|
+
<td width="50%" align="center">
|
72
|
+
|
73
|
+
<span style="position: relative; top: 8px;">範囲</span>
|
74
|
+
|
75
|
+
<div style="margin-top: 10px;" id="filter_div"></div>
|
76
|
+
|
77
|
+
<!-- <span style="color: white;">0</span> -->
|
78
|
+
|
79
|
+
</td>
|
80
|
+
|
81
|
+
<td width="50%" align="center">幅:
|
82
|
+
|
83
|
+
<span id="bucketSize" style="color:#999; font-size: 15px; text-decoration: none;"></span>
|
84
|
+
|
85
|
+
<input id="bucketSlider" type="hidden" class="bucketSlider" value="0" onchange="changeOptions();"
|
86
|
+
|
87
|
+
style="margin-top: 0px;" />
|
88
|
+
|
89
|
+
</td>
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
</tr>
|
94
|
+
|
95
|
+
</table>
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<script>
|
100
|
+
|
101
|
+
$('.bucketSlider').jRange({
|
102
|
+
|
103
|
+
from: 0,
|
104
|
+
|
105
|
+
to: 500,
|
106
|
+
|
107
|
+
showLabels: false,
|
108
|
+
|
109
|
+
snap: true
|
110
|
+
|
111
|
+
});
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
$(function () {
|
116
|
+
|
117
|
+
// 初期
|
118
|
+
|
119
|
+
$('#bucketSize').html($('#bucketSlider').val());
|
120
|
+
|
121
|
+
$('#bucketSlider').on('input change', function() {
|
122
|
+
|
123
|
+
// 変動
|
124
|
+
|
125
|
+
$('#bucketSize').html($(this).val());
|
126
|
+
|
127
|
+
});
|
128
|
+
|
129
|
+
});
|
130
|
+
|
131
|
+
</script>
|
132
|
+
|
133
|
+
</div>
|
134
|
+
|
135
|
+
</body>
|
136
|
+
|
137
|
+
</html>
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
```js
|
146
|
+
|
147
|
+
// Load the Visualization API and the controls package.
|
148
|
+
|
149
|
+
google.charts.load('current', { 'packages': ['corechart', 'controls','bar'] });
|
150
|
+
|
151
|
+
google.setOnLoadCallback(getJson);
|
152
|
+
|
153
|
+
let chart;
|
154
|
+
|
155
|
+
let thres;
|
156
|
+
|
157
|
+
let scale;
|
158
|
+
|
159
|
+
let dataArray = [['','ダミー']];
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
//チャート表示処理
|
166
|
+
|
167
|
+
function drawChart(thres){
|
168
|
+
|
169
|
+
let chartdata = google.visualization.arrayToDataTable(dataArray);
|
170
|
+
|
171
|
+
$('table').hide();
|
172
|
+
|
173
|
+
// ヒストグラムの場合
|
174
|
+
|
175
|
+
if(thres == 1){
|
176
|
+
|
177
|
+
$('table').show();
|
178
|
+
|
179
|
+
// Create a dashboard.
|
180
|
+
|
181
|
+
let dashboard = new google.visualization.Dashboard(
|
182
|
+
|
183
|
+
document.getElementById('dashboard_div'));
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
// Create a range slider, passing some options
|
188
|
+
|
189
|
+
let donutRangeSlider = new google.visualization.ControlWrapper({
|
190
|
+
|
191
|
+
'controlType': 'NumberRangeFilter',
|
192
|
+
|
193
|
+
'containerId': 'filter_div',
|
194
|
+
|
195
|
+
'options': {
|
196
|
+
|
197
|
+
'filterColumnLabel': 'ダミー'
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
});
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
// Create a pie chart, passing some options
|
206
|
+
|
207
|
+
let Histogram= new google.visualization.ChartWrapper({
|
208
|
+
|
209
|
+
'chartType': 'Histogram',
|
210
|
+
|
211
|
+
'containerId': 'chart_div',
|
212
|
+
|
213
|
+
'options': {
|
214
|
+
|
215
|
+
'width': 900,
|
216
|
+
|
217
|
+
'height': 600,
|
218
|
+
|
219
|
+
'pieSliceText': 'value',
|
220
|
+
|
221
|
+
'legend': 'right',
|
222
|
+
|
223
|
+
'histogram': {
|
224
|
+
|
225
|
+
hideBucketItems: true,
|
226
|
+
|
227
|
+
bucketSize: 10
|
228
|
+
|
229
|
+
},
|
230
|
+
|
231
|
+
'bar': { groupWidth: "100%" },
|
232
|
+
|
233
|
+
'colors': ['gray']
|
234
|
+
|
235
|
+
},
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
});
|
240
|
+
|
241
|
+
dashboard.bind(donutRangeSlider, Histogram);
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
dashboard.draw(dataArray);
|
246
|
+
|
247
|
+
changeOptions = function () {
|
248
|
+
|
249
|
+
Histogram.setOption('histogram.bucketSize', document.getElementById('bucketSlider').value);
|
250
|
+
|
251
|
+
console.log(document.getElementById('bucketSlider').value);
|
252
|
+
|
253
|
+
dashboard.draw(dataArray);
|
254
|
+
|
255
|
+
};
|
256
|
+
|
257
|
+
棒グラフの場合
|
258
|
+
|
259
|
+
}else if(thres == 2){
|
260
|
+
|
261
|
+
let options = {
|
262
|
+
|
263
|
+
title: '',
|
264
|
+
|
265
|
+
hAxis: {
|
266
|
+
|
267
|
+
format: '',
|
268
|
+
|
269
|
+
},
|
270
|
+
|
271
|
+
bars: 'horizontal'
|
272
|
+
|
273
|
+
};
|
274
|
+
|
275
|
+
let chart = new google.charts.Bar(document.getElementById('chart_div'));
|
276
|
+
|
277
|
+
chart.draw(chartdata, google.charts.Bar.convertOptions(options));
|
278
|
+
|
279
|
+
//円グラフの場合
|
280
|
+
|
281
|
+
}else if(thres == 4){
|
282
|
+
|
283
|
+
let options = {
|
284
|
+
|
285
|
+
//title: '妊婦登録時 妊娠分娩歴3 産科合併症の有無(全員)',
|
286
|
+
|
287
|
+
pieSliceText: 'none',
|
288
|
+
|
289
|
+
//colors: ['#3265a8', '#bddeff']
|
290
|
+
|
291
|
+
};
|
292
|
+
|
293
|
+
let chart = new google.visualization.PieChart(document.getElementById('chart_div'));
|
294
|
+
|
295
|
+
chart.draw(chartdata, options);
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
dataArray = [['','ダミー']];
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
//Json取得処理
|
306
|
+
|
307
|
+
function getJson(){
|
308
|
+
|
309
|
+
$('#search').click(function() {
|
310
|
+
|
311
|
+
let hostUrl = "http://localhost:3000/result/" + $('#zip').val();
|
312
|
+
|
313
|
+
$.ajax({
|
314
|
+
|
315
|
+
type: 'get',
|
316
|
+
|
317
|
+
url: hostUrl,
|
318
|
+
|
319
|
+
dataType : 'json'
|
320
|
+
|
321
|
+
}).done(function(data){
|
322
|
+
|
323
|
+
console.log("success");
|
324
|
+
|
325
|
+
//Jsonデータのbreaks,countをGoogleChartのデータ配列に格納
|
326
|
+
|
327
|
+
let data_item = data.count.map((c, i) => {
|
328
|
+
|
329
|
+
return [data.breaks[i].toString(), c];
|
330
|
+
|
331
|
+
});
|
332
|
+
|
333
|
+
dataArray.push(...data_item);
|
334
|
+
|
335
|
+
console.log(dataArray);
|
336
|
+
|
337
|
+
thres = data.thres;
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
drawChart(data.thres);
|
342
|
+
|
343
|
+
}).fail(function(){
|
344
|
+
|
345
|
+
alert('データが無いです');
|
346
|
+
|
347
|
+
$('#zip').val("");
|
348
|
+
|
349
|
+
});
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
});
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
```
|
20
362
|
|
21
363
|
|
22
364
|
|