你好,我想将一个值与以这种形式在PHP中返回值的日期关联起来:
{amount: "4580.000000", month: "07-2018"}
{amount: "2290.000000", month: "08-2018"}
{amount: "31390.000000", month: "09-2018"}
{amount: "43010.000000", month: "10-2018"}
当前的第一位数字应从7月开始,其他月份的0则应显示0
我的js:
var chiffreDaffaire = new Array();
{foreach $ca as $c}
chiffreDaffaire.push({
amount: '{$c.amount}',
month: '{$c.md}'
});
{/foreach}
var chiffres = new Array();
for (i=0; i<chiffreDaffaire.length; i++) {
chiffres.push(chiffreDaffaire[i]['amount']);
}
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: getMonths(),
datasets: [{
data: chiffres,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
}]
},
options: {
responsive: true,
title: {
display: true,
text: 'Chiffre d\'affaire - année 2018'
},
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'month'
},
scaleLabel: {
display: true,
labelString: 'Date'
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Chiffre d\'affaire'
},
ticks: {
beginAtZero:true
}
}]
}
}
});
function getMonths() {
var months = [];
months = Array.apply(0, Array(12)).map(function(_,i){
return moment().month(i).toISOString()
});
return months;
}
这是我的带有Chartsjs的JS文件,用于处理此部分
谢谢您的帮助。