-
-
Notifications
You must be signed in to change notification settings - Fork 286
/
JS code.js
46 lines (38 loc) · 1.07 KB
/
JS code.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
async function getChartData() {
const days = await api.runOnBackend(() => {
const notes = api.getNotesWithLabel('体重');
const days = [];
for (const note of notes) {
const date = note.getLabelValue('dateNote');
const weight = parseFloat(note.getLabelValue('体重'));
if (date && weight) {
days.push({ date, weight });
}
}
days.sort((a, b) => a.date > b.date ? 1 : -1);
return days;
});
const datasets = [
{
label: "体重 (kg)",
backgroundColor: 'red',
borderColor: 'red',
data: days.map(day => day.weight),
fill: false,
spanGaps: true,
datalabels: {
display: false
},
tension: 0.3
}
];
return {
datasets: datasets,
labels: days.map(day => day.date)
};
}
const ctx = api.$container.find("canvas")[0].getContext("2d");
new chartjs.Chart(ctx, {
type: 'line',
data: await getChartData()
});