From 3fd02681d178298551b0f8f3bba93964be30d4ca Mon Sep 17 00:00:00 2001 From: stilbruch Date: Sat, 7 May 2022 15:29:51 -0500 Subject: Basic progress graphs work --- app/static/js/chart.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'app/static') 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(); } -- cgit v1.2.3