Answer the question
In order to leave comments, you need to log in
How to use array values in chart.js data and label field?
I want to pass array values to data fields. I am fetching json data and storing it in an array.
var data = JSON.parse('<?=$json;?>');
// Labels
data.forEach(function (entry) {
console.log(entry.month + ' ' + entry.year);
});
// Data
data.forEach(function (entry) {
console.log(entry.cnt);
});
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [], // ???
type: 'line',
defaultFontFamily: 'Poppins',
datasets: [{
data: [], // ???
label: "Количество заявок",
backgroundColor: 'rgba(0,103,255,.15)',
borderColor: 'rgba(0,103,255,0.5)',
borderWidth: 3.5,
pointStyle: 'circle',
pointRadius: 5,
pointBorderColor: 'transparent',
pointBackgroundColor: 'rgba(0,103,255,0.5)',
},]
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question