Paramétrer l'affichage d'un graphique Chart
Bonjour,
J'essaye d'afficher un graphique Chart sur ma page mais j'ai du mal à construire mon code javascript pour pouvoir récupérer l'affichage et les bonnes données dans le graph. Je n'obtiens qu'un cadre avec la grille et pas de courbe.
Merci pour votre aide et voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| function grapheSemaineCommande_3(){
var nCpt = 0;
var aDataGraphe = []
var aLabelGraphe = ['Semaine en cours'] ;
$.ajax({
type: "GET",
url: "./donnes.xml",
dataType: "xml",
crossDomain: true,
error: function (e) {
alert("An error occurred while processing XML file");
console.log("XML reading Failed: ", e);
},
success: function (response){
$(response).find('Commande_client').each( function() {
$(this).find('semaine_mois_en_cours').each( function() {
$(this).find('nb_cmde_semaine').each ( function () {
var _attr = '21' + $(this).attr('semaine');
var _val = $(this).text();
aDataGraphe.push({week:_attr, value:parseInt(_val)}) ;
});
afficheGrapheCourbe_3(aLabelGraphe, aDataGraphe);
});
});
},
});
}
function afficheGrapheCourbe_3(aLabel, aData){
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: aLabel,
datasets: [{
label: 'semaine',
data: aData,
backgroundColor: "rgba(153,255,51,0.4)"
}]
}
});
} |