-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart.js
More file actions
56 lines (49 loc) · 1.46 KB
/
chart.js
File metadata and controls
56 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var ctx = document.getElementById('myChart').getContext('2d');
var chartContainer = document.getElementById('chart-container');
let labels = [];
let data = [];
chartContainer.appendChild(ctx.canvas);
document.getElementById('startAnimationButton').addEventListener('click', resetChart);
document.getElementById('stopAnimationButton').addEventListener('click', resetChart);
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Number of Circles',
data: data,
backgroundColor: 'rgba(0, 125, 251, 1)',
borderColor: 'rgba(0, 125, 251, 1)',
borderWidth: 2,
pointRadius: 0 // ポイントの半径を0に設定
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
setInterval(() => {
if (isAnimating){
const now = new Date();
labels.push(Math.round((Date.now() - startTime) / 1000));
data.push(circles.length);
// グラフを更新
chart.data.labels = labels;
chart.data.datasets[0].data = data;
}
chart.update();
}, 1000);
function resetChart() {
startTime = Date.now();
labels = []; // ラベルをクリア
data = []; // データをクリア
chart.data.labels = []; // ラベルをクリア
chart.data.datasets.forEach((dataset) => {
dataset.data = []; // データをクリア
});
chart.update(); // グラフを再描画
}