-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweightChart.js
More file actions
48 lines (47 loc) · 1.14 KB
/
weightChart.js
File metadata and controls
48 lines (47 loc) · 1.14 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
export default async function weightChart(weightHistory){
let data = await getData(weightHistory);
const ctx = document.getElementById('chart').getContext('2d');
if(data.xlabels.length > 0){
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: data.xlabels,
datasets: [{
label: 'Weight Chart',
data: data.yweight,
pointRadius: 0,
fill: false,
backgroundColor:
'rgba(54, 162, 235, 0.2)'
,
borderColor:
'rgba(255, 99, 132, 1)'
,
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
// Include a units in the ticks
callback: function(value, index, values) {
return value + 'kg';
}
}
}]
}
}
});
}
}
function getData(weightHistory){
let xlabels=[];
let yweight=[];
weightHistory.forEach((record) => {
xlabels.push(record.date);
yweight.push(record.weight);
})
// console.log(xlabels, yweight);
return {xlabels, yweight};
}