質問編集履歴

2

コード追記

2018/11/25 12:51

投稿

mastan1117
mastan1117

スコア16

test CHANGED
File without changes
test CHANGED
@@ -43,3 +43,293 @@
43
43
  何か追加でほしい情報等あれば追加します。
44
44
 
45
45
  宜しくお願い致します。
46
+
47
+
48
+
49
+
50
+
51
+ 10/22追記
52
+
53
+ ```Html
54
+
55
+
56
+
57
+ <%@ page language="java" contentType="text/html; charset=UTF-8"
58
+
59
+ pageEncoding="UTF-8"%>
60
+
61
+ <!DOCTYPE html>
62
+
63
+ <html>
64
+
65
+ <head>
66
+
67
+ <meta charset="UTF-8">
68
+
69
+ <title>hogeTitle</title>
70
+
71
+
72
+
73
+ <script type="text/javascript" charset="UTF-8" src="${pageContext.request.contextPath}/js/Chart.js"></script>
74
+
75
+ <script type="text/javascript" charset="UTF-8" src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
76
+
77
+
78
+
79
+ <script type="text/JavaScript">
80
+
81
+ // 取得してきたデータを画面に反映する
82
+
83
+ function setjsondata(json_key, json_value) {
84
+
85
+ var a = json_value;
86
+
87
+ document.getElementById('GraphBDiv').innerHTML = "<br />";
88
+
89
+ document.getElementById('GraphBDiv').innerHTML = a;
90
+
91
+ }
92
+
93
+ </script>
94
+
95
+
96
+
97
+ </head>
98
+
99
+ <body style="height: 100%; margin: 0%; background-color: #494949">
100
+
101
+
102
+
103
+ <div style="width: 50%; height: 100%; float: left;">
104
+
105
+ <table width="100%" style="margin-top: 30px;">
106
+
107
+ <tr align="center">
108
+
109
+ <td style="color: white; width: 70%"><%= request.getAttribute("pageTitle" )%></td>
110
+
111
+ <input type='hidden' id='pageDisp' value= '<%= request.getAttribute("pageTitle" )%>' >
112
+
113
+ <td style="color: white; width: 30%"><button type="button" class="btn" autofocus="true">グラフ切り替え</button></td>
114
+
115
+ </tr>
116
+
117
+ </table>
118
+
119
+ <p style="margin-top: 50px;">
120
+
121
+ <canvas id="GraphA" width="600" height="500"
122
+
123
+ style="background-color: #494949;"></canvas>
124
+
125
+ </p>
126
+
127
+ </div>
128
+
129
+
130
+
131
+ <div style="width: 50%; height: 100%; float: right;">
132
+
133
+ <div id="GraphBDiv" style="width: 100%; height: 50%;">
134
+
135
+ </div>
136
+
137
+ <div style="width: 100%; height: 50%;">
138
+
139
+ </div>
140
+
141
+ </div>
142
+
143
+ <script>
144
+
145
+ var ctx = document.getElementById("GraphA");
146
+
147
+ var myChart = new Chart(
148
+
149
+ ctx,
150
+
151
+ {
152
+
153
+ type : 'bar',
154
+
155
+ data: {
156
+
157
+ labels: ["昨日", "今日"],
158
+
159
+ datasets: [
160
+
161
+ {
162
+
163
+ label: "データ1",
164
+
165
+ borderWidth:1,
166
+
167
+ backgroundColor: "#EFEA5A",
168
+
169
+ borderColor: "#EFEA5A",
170
+
171
+ data: [23, 54]
172
+
173
+ },{
174
+
175
+ label: "データ2",
176
+
177
+ borderWidth:1,
178
+
179
+ backgroundColor: "#048BA8",
180
+
181
+ borderColor: "#048BA8",
182
+
183
+ data: [25, 22]
184
+
185
+ }]
186
+
187
+
188
+
189
+ },
190
+
191
+ options : {
192
+
193
+ responsive : true,
194
+
195
+
196
+
197
+ title : {
198
+
199
+ display : true,
200
+
201
+ text : 'グラフA',
202
+
203
+ padding : 3,
204
+
205
+ fontColor : "#fff",
206
+
207
+ fontSize: 15
208
+
209
+ },
210
+
211
+ scales : {
212
+
213
+ xAxes : [ {
214
+
215
+ ticks : {
216
+
217
+ fontColor : "#fff",
218
+
219
+ fontSize: 15
220
+
221
+ },
222
+
223
+ stacked : true,
224
+
225
+ categoryPercentage : 0.4,
226
+
227
+ fontSize: 15
228
+
229
+ } ],
230
+
231
+ yAxes : [ {
232
+
233
+ ticks : {
234
+
235
+ fontColor : "#fff",
236
+
237
+ },
238
+
239
+ stacked : true,
240
+
241
+ fontSize: 15
242
+
243
+ } ]
244
+
245
+ },
246
+
247
+ legend : {
248
+
249
+ labels : {
250
+
251
+ boxWidth : 20,
252
+
253
+ padding : 20,
254
+
255
+ fontColor : "#fff",
256
+
257
+ fontSize: 14
258
+
259
+ },
260
+
261
+ display : true
262
+
263
+ },
264
+
265
+ onClick : function(event, activeElements) {
266
+
267
+ if (activeElements.length) {
268
+
269
+ var hoge1 = "ほげ";
270
+
271
+ var hoge2 = "ほげ";
272
+
273
+
274
+
275
+ var postData = {
276
+
277
+ 'hoge1':hoge1,
278
+
279
+ 'hoge2':hoge2,
280
+
281
+ };
282
+
283
+ var postUrl = "/HogeProject/Hoge(web.xmlで指定したサーブレット)";
284
+
285
+ $.ajax({
286
+
287
+ url: postUrl,
288
+
289
+ type: "POST",
290
+
291
+ dataType: "json",
292
+
293
+ data: postData,
294
+
295
+ success: function(json){
296
+
297
+ if(json["status"] == "error"){
298
+
299
+ alert(json["message"]);
300
+
301
+ return false;
302
+
303
+ }
304
+
305
+ for(var j in json){
306
+
307
+ setjsondata(j, json[j]);
308
+
309
+ }
310
+
311
+ }
312
+
313
+ });
314
+
315
+ }
316
+
317
+ }
318
+
319
+ }
320
+
321
+ });
322
+
323
+ </script>
324
+
325
+
326
+
327
+ </body>
328
+
329
+ </html>
330
+
331
+ ```
332
+
333
+
334
+
335
+ グラフAのデータをクリックするとグラフBが表示されるというのが期待結果です。

1

追記

2018/11/25 12:51

投稿

mastan1117
mastan1117

スコア16

test CHANGED
File without changes
test CHANGED
@@ -32,6 +32,14 @@
32
32
 
33
33
 
34
34
 
35
+
36
+
37
+ innerHTMLにcanvasタグやscriptタグは使用できないなどの場合があるなら
38
+
39
+ どういうアプローチをして実現できるのかのアドバイスももらえると嬉しいです。
40
+
41
+
42
+
35
43
  何か追加でほしい情報等あれば追加します。
36
44
 
37
45
  宜しくお願い致します。