You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
796 B

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'
}]
}
}
});
});
})
}