diff options
| author | stilbruch <stilbruch@protonmail.com> | 2022-05-07 15:29:51 -0500 |
|---|---|---|
| committer | stilbruch <stilbruch@protonmail.com> | 2022-05-07 15:29:51 -0500 |
| commit | 3fd02681d178298551b0f8f3bba93964be30d4ca (patch) | |
| tree | 2201ba58b6dfc680c3d2e8c835db020308798cb6 /app/static | |
| parent | 970277e71272687c16d75ffa73fcbb461a1fee80 (diff) | |
| download | Strengthy-3fd02681d178298551b0f8f3bba93964be30d4ca.tar.xz Strengthy-3fd02681d178298551b0f8f3bba93964be30d4ca.zip | |
Basic progress graphs work
Diffstat (limited to 'app/static')
| -rw-r--r-- | app/static/js/chart.js | 23 |
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(); } |
