-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChartConfig.js
136 lines (104 loc) · 2.86 KB
/
ChartConfig.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const ctx = document.getElementById("myChart").getContext("2d");
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'E[T]',
data: [],
backgroundColor: 'rgba(255, 0, 0, 0.2)',
borderColor: 'rgba(255, 0, 0, 1)',
borderWidth: 1,
pointRadius: 0
},
{
label: 'E[W]',
data: [],
backgroundColor: 'rgba(0, 255, 0, 0.2)',
borderColor: 'rgba(0, 255, 0, 1)',
borderWidth: 1,
pointRadius: 0
},
{
label: 'E[U]',
data: [],
backgroundColor: 'rgba(255, 0, 255, 0.2)',
borderColor: 'rgba(255, 0, 255, 1)',
borderWidth: 1,
pointRadius: 0
},
{
label: 'E[N]',
data: [],
backgroundColor: 'rgba(200, 200, 50, 0.2)',
borderColor: 'rgba(200, 200, 50, 1)',
borderWidth: 1,
pointRadius: 0
},
{
label: 'E[B]',
data: [],
backgroundColor: 'rgba(24, 24, 124, 0.2)',
borderColor: 'rgba(24, 24, 124, 1)',
borderWidth: 1,
pointRadius: 0
}]
},
options: {
width: 100,
height: 100,
maintainAspectRatio: false,
responsive: true,
scales: {
yAxes: [{
gridLines: {
display:false
},
ticks: {
beginAtZero:true
}
}],
xAxes: [{
gridLines: {
display:false
},
ticks: {
beginAtZero:true
}
}]
}
}
});
var updateChart = function(datasetIndex, newData) {
const dataLength = chart.config.data.datasets[datasetIndex].data.length;
if(newData != "NaN" ) {
chart.config.data.datasets[datasetIndex].data.push(newData);
}
else {
chart.config.data.datasets[datasetIndex].data.push(0);
}
// if(chart.config.data.datasets[datasetIndex].length > 200){
// chart.config.data.datasets[datasetIndex].splice(0, 1);
// }
}
var updateChartView = function(){
chart.update();
}
var insertInChart = function(){
updateChart(0, metrics.T);
updateChart(1, metrics.W);
updateChart(2, metrics.U);
updateChart(3, metrics.N);
updateChart(4, metrics.B);
chart.data.labels.push("");
// if(chart.data.labels.length > 200) {
// chart.data.labels.splice(0, 1);
// }
}
var resetChart = function() {
chart.data.labels = [];
for(var datasetIdx in chart.config.data.datasets) {
chart.config.data.datasets[datasetIdx].data = [];
}
chart.update();
}