How would I format data using for() and putting that data inside datasets in Chart.js.
I tried and it's only showing the date labels and not the marks, but when I add data manually without using the data from inside for() everything works like it should.
var date = [];
var marks = [];
for (var i in data) {
date.push(data[i].timestamp); // timestamp
marks.push(data[i].count); // votes
}
new Chart('myChart', {
type: 'line',
data: {
datasets: [{
label: 'votes',
data: [{
'date': '11/11',
'votes': 55
},
{
'date': '5/11',
'votes': 13
}
],
borderColor: 'grey',
backgroundColor: 'rgba(0, 0, 255, 0.5)'
}]
},
options: {
parsing: {
xAxisKey: 'date',
yAxisKey: 'marks'
},
scales: {
y: {
ticks: {
stepSize: 1
}
},
x: {
type: 'time',
time: {
parser: 'DD/MM/YY',
unit: 'day',
tooltipFormat: 'MMM DD'
}
},
xAxes: [{
type: 'time',
time: {
unit: 'month'
}
}],
}
}