From da1f23c853a5bf6d8824abe29f393a9793533561 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Wed, 25 Jan 2017 19:19:30 -0500 Subject: [PATCH] basic app --- app.js | 41 +++++++++++++++++++++++++++++++++++++++++ index.html | 13 +++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 app.js create mode 100644 index.html diff --git a/app.js b/app.js new file mode 100644 index 0000000..94ce420 --- /dev/null +++ b/app.js @@ -0,0 +1,41 @@ +window.onload = function(){ + var ctx = document.querySelector('#runs'); + + var chartData = { + labels: [], + datasets: [] + }; + + fetch('http://localhost:3000/users/').then(function(response){ + response.json().then(function(data){ + data.forEach(function(user, index){ + var newUserObj = { + label: "Runs for " + user.name, + data: [] + }; + user.runs.forEach(function(run){ + var date = new Date(run.date); + newUserObj.data.push({ + // x: date.toLocaleString(), + x: date, + y: run.distance + }); + }) + chartData.datasets.push(newUserObj); + }); + + var runsChart = new Chart(ctx, { + type: 'line', + data: chartData, + options: { + scales: { + xAxes: [{ + type: 'time', + position: 'bottom' + }] + } + } + }); + }); + }) +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..a4aeb2d --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + + + + + + +