質問編集履歴
5
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,156 +13,6 @@
|
|
13
13
|
|
14
14
|
解決策をご存知の方がいらっしゃいましたら何卒ご教授お願い致します。
|
15
15
|
|
16
|
-
```ここに言語を入力
|
17
|
-
<div class="container" style="width:100%">
|
18
|
-
<canvas id="myBarChart1" width="800" height="400"></canvas>
|
19
|
-
|
20
|
-
<script>
|
21
|
-
//棒グラフ
|
22
|
-
var ctx = document.getElementById("myBarChart1");
|
23
|
-
var myBarChart = new Chart(ctx, {
|
24
|
-
//グラフの種類
|
25
|
-
type: 'bar',
|
26
|
-
//データの設定
|
27
|
-
data: {
|
28
|
-
labels: ["Before 3 years","Before 2 years","Before 1 year","Start", "After 1 year", "After 2 years", "After 3 years"],
|
29
|
-
datasets: [{
|
30
|
-
backgroundColor: ["rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)", "rgba(75,192,192,1)", "rgba(75,192,192,1)", "rgba(75,192,192,1)"],
|
31
|
-
//グラフのデータ
|
32
|
-
data: [0.7,0.8,0.7,1, 2.1, 8.1, 10.1]
|
33
|
-
}
|
34
|
-
|
35
|
-
]
|
36
|
-
},
|
37
|
-
//オプションの設定
|
38
|
-
options: {
|
39
|
-
animation: {
|
40
|
-
duration: 8000,
|
41
|
-
},
|
42
|
-
|
43
|
-
//軸の設定
|
44
|
-
scales: {
|
45
|
-
//縦軸の設定
|
46
|
-
yAxes: [{
|
47
|
-
display: true,
|
48
|
-
stacked: false,
|
49
|
-
gridLines: {
|
50
|
-
display: false
|
51
|
-
}
|
52
|
-
}],
|
53
|
-
xAxes: [{
|
54
|
-
display: true,
|
55
|
-
stacked: false,
|
56
|
-
gridLines: {
|
57
|
-
display: false
|
58
|
-
}
|
59
|
-
}]
|
60
|
-
},
|
61
|
-
tooltips: {
|
62
|
-
callbacks: {
|
63
|
-
label: function (tooltipItem, data) {
|
64
|
-
return data.labels[tooltipItem.index]
|
65
|
-
+ ": "
|
66
|
-
+ data.datasets[0].data[tooltipItem.index]
|
67
|
-
+ " 倍";
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
});
|
73
|
-
|
74
|
-
</script>
|
75
|
-
|
76
|
-
<script>
|
77
|
-
var ctx = document.getElementById("myChart");
|
78
|
-
var myChart= new Chart(ctx, {
|
79
|
-
type: type,
|
80
|
-
data: data,
|
81
|
-
options: options
|
82
|
-
|
83
|
-
|
84
|
-
});
|
85
|
-
</script>
|
86
|
-
|
87
|
-
</div>
|
88
|
-
|
89
|
-
|
90
|
-
<canvas id="myLineChart" width="800" height="400"></canvas>
|
91
|
-
|
92
|
-
<script>
|
93
|
-
|
94
|
-
//折れ線グラフ
|
95
|
-
var ctx = document.getElementById("myLineChart");
|
96
|
-
var myLineChart = new Chart(ctx, {
|
97
|
-
//グラフの種類
|
98
|
-
type: 'line',
|
99
|
-
//データの設定
|
100
|
-
data: {
|
101
|
-
//データ項目のラベル
|
102
|
-
labels: ["Before 3 years","Before 2 years","Before 1 year","Start", "After 1 year", "After 2 years", "After 3 years"],
|
103
|
-
//データセット
|
104
|
-
datasets: [{
|
105
|
-
label: "転換率",
|
106
|
-
borderWidth: 3,
|
107
|
-
backgroundColor: "rgba(75,192,192,0.4)",
|
108
|
-
borderColor: ["rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)", "rgba(75,192,192,1)", "rgba(75,192,192,1)", "rgba(75,192,192,1)"],
|
109
|
-
pointBorderColor: "#fff",
|
110
|
-
pointBackgroundColor: ["rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)", "rgba(75,192,192,1)", "rgba(75,192,192,1)", "rgba(75,192,192,1)"],
|
111
|
-
pointRadius: 8,
|
112
|
-
pointBorderWidth: 5,
|
113
|
-
pointHoverRadius: 10,
|
114
|
-
pointHitRadius: 5,
|
115
|
-
pointStyle: "circle",
|
116
|
-
pointHoverBackgroundColor: ["rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)", "rgba(75,192,192,1)", "rgba(75,192,192,1)", "rgba(75,192,192,1)"],
|
117
|
-
pointHoverBorderColor: "#fff",
|
118
|
-
pointHitRadius: 5,
|
119
|
-
//グラフのデータ
|
120
|
-
data: [1.06,1.37,1.23,1.49, 2.09, 3.27, 3.31]
|
121
|
-
}]
|
122
|
-
},
|
123
|
-
//オプションの設定
|
124
|
-
options: {
|
125
|
-
animation: {
|
126
|
-
duration: 8000
|
127
|
-
},
|
128
|
-
tooltips: {
|
129
|
-
callbacks: {
|
130
|
-
label: function (tooltipItem, data) {
|
131
|
-
return data.labels[tooltipItem.index]
|
132
|
-
+ ": "
|
133
|
-
+ data.datasets[0].data[tooltipItem.index]
|
134
|
-
+ " %"; //ここで単位を付けます
|
135
|
-
}
|
136
|
-
}
|
137
|
-
},
|
138
|
-
scales: {
|
139
|
-
//縦軸の設定
|
140
|
-
yAxes: [{
|
141
|
-
display: true,
|
142
|
-
stacked: false,
|
143
|
-
gridLines: {
|
144
|
-
display: false
|
145
|
-
}
|
146
|
-
}],
|
147
|
-
xAxes: [{
|
148
|
-
display: true,
|
149
|
-
stacked: false,
|
150
|
-
gridLines: {
|
151
|
-
display: false
|
152
|
-
}
|
153
|
-
}],
|
154
|
-
ticks: {
|
155
|
-
//最小値を0にする
|
156
|
-
beginAtZero: true
|
157
|
-
}
|
158
|
-
}
|
159
|
-
}
|
160
|
-
});
|
161
|
-
</script>
|
162
|
-
```
|
163
|
-

|
164
|
-
|
165
|
-
|
166
16
|
2017/11/08
|
167
17
|
・進捗状況
|
168
18
|
ツールチップ常時表示、線グラフの色分け、ラベルの非表示が解決いたしました。
|
@@ -173,8 +23,51 @@
|
|
173
23
|
```ここに言語を入力
|
174
24
|
<script>
|
175
25
|
//ツールチップ常時表示
|
26
|
+
Chart.pluginService.register({
|
27
|
+
beforeRender: function (chart) {
|
28
|
+
if (chart.config.options.showAllTooltips) {
|
176
|
-
//
|
29
|
+
// create an array of tooltips
|
30
|
+
// we can't use the chart tooltip because there is only one tooltip per chart
|
31
|
+
chart.pluginTooltips = [];
|
32
|
+
chart.config.data.datasets.forEach(function (dataset, i) {
|
33
|
+
chart.getDatasetMeta(i).data.forEach(function (sector, j) {
|
34
|
+
chart.pluginTooltips.push(new Chart.Tooltip({
|
35
|
+
_chart: chart.chart,
|
36
|
+
_chartInstance: chart,
|
37
|
+
_data: chart.data,
|
38
|
+
_options: chart.options.tooltips,
|
39
|
+
_active: [sector]
|
40
|
+
}, chart));
|
41
|
+
});
|
42
|
+
});
|
177
43
|
|
44
|
+
// turn off normal tooltips
|
45
|
+
chart.options.tooltips.enabled = false;
|
46
|
+
}
|
47
|
+
},
|
48
|
+
afterDraw: function (chart, easing) {
|
49
|
+
if (chart.config.options.showAllTooltips) {
|
50
|
+
// we don't want the permanent tooltips to animate, so don't do anything till the animation runs atleast once
|
51
|
+
if (!chart.allTooltipsOnce) {
|
52
|
+
if (easing !== 1)
|
53
|
+
return;
|
54
|
+
chart.allTooltipsOnce = true;
|
55
|
+
}
|
56
|
+
|
57
|
+
// turn on tooltips
|
58
|
+
chart.options.tooltips.enabled = true;
|
59
|
+
Chart.helpers.each(chart.pluginTooltips, function (tooltip) {
|
60
|
+
tooltip.initialize();
|
61
|
+
tooltip.update();
|
62
|
+
// we don't actually need this since we are not animating tooltips
|
63
|
+
tooltip.pivot();
|
64
|
+
tooltip.transition(easing).draw();
|
65
|
+
});
|
66
|
+
chart.options.tooltips.enabled = false;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
});
|
70
|
+
|
178
71
|
//棒グラフ
|
179
72
|
var ctx = document.getElementById("myBarChart1");
|
180
73
|
var myBarChart = new Chart(ctx, {
|
4
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -316,7 +316,6 @@
|
|
316
316
|
}
|
317
317
|
}
|
318
318
|
},
|
319
|
-
showAllTooltips: true,
|
320
319
|
scales: {
|
321
320
|
//縦軸の設定
|
322
321
|
yAxes: [{
|
3
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -160,4 +160,186 @@
|
|
160
160
|
});
|
161
161
|
</script>
|
162
162
|
```
|
163
|
-

|
163
|
+

|
164
|
+
|
165
|
+
|
166
|
+
2017/11/08
|
167
|
+
・進捗状況
|
168
|
+
ツールチップ常時表示、線グラフの色分け、ラベルの非表示が解決いたしました。
|
169
|
+
ただ、線グラフ"After 1 year"以降のツールチップ内のデータが"undefined%"と表示されてしまいます。
|
170
|
+
あと、ツールチップ内のラベル名が重複してしまっているので1つに絞りたいと考えています。
|
171
|
+
重ねてのお願いで恐縮ですが、ご教示頂けますと幸いです。
|
172
|
+
|
173
|
+
```ここに言語を入力
|
174
|
+
<script>
|
175
|
+
//ツールチップ常時表示
|
176
|
+
//文字数制限の為割愛
|
177
|
+
|
178
|
+
//棒グラフ
|
179
|
+
var ctx = document.getElementById("myBarChart1");
|
180
|
+
var myBarChart = new Chart(ctx, {
|
181
|
+
//グラフの種類
|
182
|
+
type: 'bar',
|
183
|
+
//データの設定
|
184
|
+
data: {
|
185
|
+
//データ項目のラベル
|
186
|
+
labels: ["Before 3 years","Before 2 years","Before 1 year","Start", "After 1 year", "After 2 years", "After 3 years"],
|
187
|
+
//データセット
|
188
|
+
datasets: [{
|
189
|
+
label: "年間売上比率",
|
190
|
+
backgroundColor: ["rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)","rgba(75,192,192,0.6)", "rgba(75,192,192,1)", "rgba(75,192,192,1)", "rgba(75,192,192,1)"],
|
191
|
+
//グラフのデータ
|
192
|
+
data: [0.7,0.8,0.7,1, 2.1, 8.1, 10.1]
|
193
|
+
}
|
194
|
+
|
195
|
+
]
|
196
|
+
},
|
197
|
+
//オプションの設定
|
198
|
+
options: {
|
199
|
+
showAllTooltips: true,
|
200
|
+
animation: {
|
201
|
+
duration: 8000,
|
202
|
+
},
|
203
|
+
legend: {
|
204
|
+
display: false,
|
205
|
+
},
|
206
|
+
//軸の設定
|
207
|
+
scales: {
|
208
|
+
//縦軸の設定
|
209
|
+
yAxes: [{
|
210
|
+
display: true,
|
211
|
+
stacked: false,
|
212
|
+
gridLines: {
|
213
|
+
display: false
|
214
|
+
}
|
215
|
+
}],
|
216
|
+
xAxes: [{
|
217
|
+
display: true,
|
218
|
+
stacked: false,
|
219
|
+
gridLines: {
|
220
|
+
display: false
|
221
|
+
}
|
222
|
+
}]
|
223
|
+
},
|
224
|
+
tooltips: {
|
225
|
+
callbacks: {
|
226
|
+
label: function (tooltipItem, data) {
|
227
|
+
return data.labels[tooltipItem.index]
|
228
|
+
+ ": "
|
229
|
+
+ data.datasets[0].data[tooltipItem.index]
|
230
|
+
+ " 倍";
|
231
|
+
}
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
}
|
238
|
+
});
|
239
|
+
|
240
|
+
</script>
|
241
|
+
|
242
|
+
|
243
|
+
</div>
|
244
|
+
|
245
|
+
|
246
|
+
<canvas id="myLineChart" width="800" height="400"></canvas>
|
247
|
+
|
248
|
+
<script>
|
249
|
+
//折れ線グラフ
|
250
|
+
var ctx = document.getElementById("myLineChart");
|
251
|
+
var myLineChart = new Chart(ctx, {
|
252
|
+
//グラフの種類
|
253
|
+
type: 'line',
|
254
|
+
//データの設定
|
255
|
+
data: {
|
256
|
+
//データ項目のラベル
|
257
|
+
labels: ["Before 3 years","Before 2 years","Before 1 year","Start", "After 1 year", "After 2 years", "After 3 years"],
|
258
|
+
//データセット
|
259
|
+
datasets: [{
|
260
|
+
// Start以前
|
261
|
+
label: "転換率",
|
262
|
+
borderWidth: 3,
|
263
|
+
backgroundColor: "rgba(75,192,192,0.4)",
|
264
|
+
borderColor: "rgba(75,192,192,0.6)",
|
265
|
+
pointBorderColor: "#fff",
|
266
|
+
pointBackgroundColor: "rgba(75,192,192,0.6)",
|
267
|
+
pointRadius: 8,
|
268
|
+
pointBorderWidth: 5,
|
269
|
+
pointHoverRadius: 10,
|
270
|
+
pointHitRadius: 5,
|
271
|
+
pointStyle: "circle",
|
272
|
+
pointHoverBackgroundColor: "rgba(75,192,192,0.6)",
|
273
|
+
pointHoverBorderColor: "#fff",
|
274
|
+
pointHitRadius: 5,
|
275
|
+
//グラフのデータ
|
276
|
+
data: [1.06,1.37,1.23,1.49]
|
277
|
+
},
|
278
|
+
{ // Start以前
|
279
|
+
label: "転換率",
|
280
|
+
borderWidth: 3,
|
281
|
+
backgroundColor: "rgba(75,192,192,0.8)",
|
282
|
+
borderColor: "rgba(75,192,192,1)",
|
283
|
+
pointBorderColor: "#fff",
|
284
|
+
pointBackgroundColor: "rgba(75,192,192,0.8)",
|
285
|
+
pointRadius: 8,
|
286
|
+
pointBorderWidth: 5,
|
287
|
+
pointHoverRadius: 10,
|
288
|
+
pointHitRadius: 5,
|
289
|
+
pointStyle: "circle",
|
290
|
+
pointHoverBackgroundColor: "rgba(75,192,192,1)",
|
291
|
+
pointHoverBorderColor: "#fff",
|
292
|
+
pointHitRadius: 5,
|
293
|
+
//グラフのデータ
|
294
|
+
data: [,,, 1.49, 2.09, 3.27, 3.31]
|
295
|
+
}
|
296
|
+
|
297
|
+
]
|
298
|
+
},
|
299
|
+
//オプションの設定
|
300
|
+
options: {
|
301
|
+
showAllTooltips: true,
|
302
|
+
animation: {
|
303
|
+
duration: 8000
|
304
|
+
},
|
305
|
+
legend: {
|
306
|
+
display: false
|
307
|
+
},
|
308
|
+
|
309
|
+
tooltips: {
|
310
|
+
callbacks: {
|
311
|
+
label: function (tooltipItem, data) {
|
312
|
+
return data.labels[tooltipItem.index]
|
313
|
+
+ ": "
|
314
|
+
+ data.datasets[0].data[tooltipItem.index]
|
315
|
+
+ " %"; //ここで単位を付けます
|
316
|
+
}
|
317
|
+
}
|
318
|
+
},
|
319
|
+
showAllTooltips: true,
|
320
|
+
scales: {
|
321
|
+
//縦軸の設定
|
322
|
+
yAxes: [{
|
323
|
+
display: true,
|
324
|
+
stacked: false,
|
325
|
+
gridLines: {
|
326
|
+
display: false
|
327
|
+
}
|
328
|
+
}],
|
329
|
+
xAxes: [{
|
330
|
+
display: true,
|
331
|
+
stacked: false,
|
332
|
+
gridLines: {
|
333
|
+
display: false
|
334
|
+
}
|
335
|
+
}],
|
336
|
+
ticks: {
|
337
|
+
//最小値を0にする
|
338
|
+
beginAtZero: true
|
339
|
+
}
|
340
|
+
}
|
341
|
+
}
|
342
|
+
});
|
343
|
+
</script>
|
344
|
+
```
|
345
|
+

|
2
追加点
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
backgroundColorを棒グラフと同様に指定しても最初のカラーが全てに適用されてしまう。
|
10
10
|
|
11
11
|
両グラフともツールチップを常時表示したままにしたい。
|
12
|
+
(可能であればアニメーション終了時に表示開始したい)
|
12
13
|
|
13
14
|
解決策をご存知の方がいらっしゃいましたら何卒ご教授お願い致します。
|
14
15
|
|
1
追加点
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
棒グラフの『start』以前と以後の色分けをしているのですが、折れ線グラフも同様に『start』以前と以後の色分けをしたい。
|
9
9
|
backgroundColorを棒グラフと同様に指定しても最初のカラーが全てに適用されてしまう。
|
10
10
|
|
11
|
+
両グラフともツールチップを常時表示したままにしたい。
|
12
|
+
|
11
13
|
解決策をご存知の方がいらっしゃいましたら何卒ご教授お願い致します。
|
12
14
|
|
13
15
|
```ここに言語を入力
|