回答編集履歴
3
消し忘れた
answer
CHANGED
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
lineGraph.data.datasets[0].data[i] = data[i];
|
|
63
63
|
lineGraph.update();
|
|
64
64
|
i++;
|
|
65
|
-
setTimeout(test,100
|
|
65
|
+
setTimeout(test,100);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
});
|
2
ちょっとよくなかったので修正
answer
CHANGED
|
@@ -29,4 +29,41 @@
|
|
|
29
29
|
setTimeout(test,100,i+1);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
##### ちょっとよくなかったので修正
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
window.addEventListener('load', function () {
|
|
38
|
+
var ctx = document.getElementById('js-line-graph');
|
|
39
|
+
var data = [40, 30, 48, 33, 30, 30, 38, 33, 28, 40, 31, 40];
|
|
40
|
+
var i = 0;
|
|
41
|
+
var lineGraph = new Chart(ctx, {
|
|
42
|
+
type: 'line',
|
|
43
|
+
data: {
|
|
44
|
+
//...
|
|
45
|
+
datasets: [
|
|
46
|
+
{
|
|
47
|
+
label: '',
|
|
48
|
+
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
49
|
+
//...
|
|
50
|
+
},
|
|
51
|
+
options: {
|
|
52
|
+
//...
|
|
53
|
+
animation:{
|
|
54
|
+
onComplete:function(animation){
|
|
55
|
+
setTimeout(test,100);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
function test(){
|
|
61
|
+
if ( i < data.length ){
|
|
62
|
+
lineGraph.data.datasets[0].data[i] = data[i];
|
|
63
|
+
lineGraph.update();
|
|
64
|
+
i++;
|
|
65
|
+
setTimeout(test,100,i);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
32
69
|
```
|
1
書式の修正
answer
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
なんか他にもっと上手い方法があるような気がしますが……
|
|
2
2
|
[サンプル](https://jsfiddle.net/Lhankor_Mhy/x4ebhgru/)
|
|
3
3
|
```js
|
|
4
|
+
window.addEventListener('load', function () {
|
|
5
|
+
var data = [40, 30, 48, 33, 30, 30, 38, 33, 28, 40, 31, 40];
|
|
6
|
+
var lineGraph = new Chart(ctx, {
|
|
7
|
+
data: {
|
|
8
|
+
//...
|
|
9
|
+
datasets: [
|
|
10
|
+
{
|
|
11
|
+
label: '',
|
|
12
|
+
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
13
|
+
//...
|
|
14
|
+
},
|
|
15
|
+
options: {
|
|
16
|
+
//...
|
|
4
17
|
animation:{
|
|
5
18
|
onComplete:function(animation){
|
|
6
19
|
setTimeout(test,100,0);
|
|
7
20
|
}
|
|
8
21
|
},
|
|
22
|
+
//...
|
|
23
|
+
}
|
|
9
|
-
|
|
24
|
+
});
|
|
10
|
-
```js
|
|
11
25
|
function test(i){
|
|
12
26
|
if ( i < data.length ){
|
|
13
27
|
lineGraph.data.datasets[0].data[i] = data[i];
|