summaryrefslogtreecommitdiff
path: root/app/static
diff options
context:
space:
mode:
Diffstat (limited to 'app/static')
-rw-r--r--app/static/js/chart.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/app/static/js/chart.js b/app/static/js/chart.js
index 06edc4d..779d8d3 100644
--- a/app/static/js/chart.js
+++ b/app/static/js/chart.js
@@ -1,4 +1,10 @@
-function exercise_chart(elem_id, exercise_id) {
+async function request(url) {
+ const response = await fetch(url);
+
+ return response.json();
+}
+
+async function exercise_chart(elem_id, exercise_id, exercise_name) {
// Create initial chart
let chart = new Chart(document.getElementById(elem_id), {
type: 'line',
@@ -8,6 +14,12 @@ function exercise_chart(elem_id, exercise_id) {
pointStyle: 'circle',
pointRadius: 5,
pointHoverRadius: 10,
+ datasets: [{
+ label: exercise_name,
+ data: [],
+ fill: false,
+ tension: 0.1
+ }]
},
option: {
scales: {
@@ -19,4 +31,13 @@ function exercise_chart(elem_id, exercise_id) {
});
// Load chart data for exercise
+ const json = await request(`/api/progress/exercise/${exercise_id}`);
+
+ json.forEach(row => {
+ chart.data.datasets[0].data.push(row[1]);
+ chart.data.labels.push(row[0]);
+ });
+
+
+ chart.update();
}