2👍
✅
You are creating a new Chart()
every time through your $.each()
loop.
Your logic goes like this:
for each (key, value) in res:
create a new Chart containing just this (key, value)
You almost certainly want this:
create empty arrays myLabels[] and myData[]
for each (key, value) in res:
add key to myLabels[]
add value to myData[]
then
create one (and only one) new Chart using myLabels[] and myData[]
Your data
property for new Chart()
will then look like this:
data: {
labels: myLabels,
datasets: [{
label: 'Labels',
data: myData,
backgroundColor: [
'rgba(75, 192, 192, 0.2)',
'rgba(255, 99, 132, 0.2)'
],
borderColor: [
'rgba(75, 192, 192, 1)',
'rgba(255,99,132,1)'
],
borderWidth: 1
}]
}
Source:stackexchange.com