let labels = [] let data = [] fetch('./address.json').then(response => { return response.json(); }).then(data => { data.sort(function(a,b){ console.log(a.date) console.log(b.date) return new Date(a.date) - new Date(b.date) ; }); console.log(data); }).catch(err => { }); var ctx = document.getElementById("myChart").getContext('2d'); var myChart = new Chart(ctx, { type: 'bar', data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [1, -1, 1, -1, 1, -1], borderWidth: 1 }] }, options: { scales: { yAxes: [{ ticks: { beginAtZero:true } }] } } });