2016-05-23 09:10:24 +00:00
|
|
|
var subPhone = $('section[data-sublink="phone"]');
|
2016-05-23 10:07:18 +00:00
|
|
|
subPhone.style.display = 'flex';
|
|
|
|
subPhone.style.flexWrap = 'wrap';
|
|
|
|
subPhone.style.justifyContent = 'space-around';
|
2016-05-23 09:10:24 +00:00
|
|
|
|
|
|
|
/* [0] Paramètres globaux
|
2016-04-19 15:08:59 +00:00
|
|
|
=========================================================*/
|
2016-05-23 09:10:24 +00:00
|
|
|
Chart.defaults.global.responsive = false;
|
2016-05-23 10:07:18 +00:00
|
|
|
Chart.defaults.global.title.display = true;
|
|
|
|
|
|
|
|
|
2016-05-23 09:10:24 +00:00
|
|
|
Chart.defaults.global.onClick = function(e, c){
|
|
|
|
console.log(e); // MouseEvent
|
2016-05-23 10:07:18 +00:00
|
|
|
if( c[0] != null )
|
|
|
|
console.log(c[0]._datasetIndex, c[0]._index); // Chart data
|
2016-05-23 09:10:24 +00:00
|
|
|
|
|
|
|
// _datasetIndex, quel dataset (s'il y en a plusieurs)
|
|
|
|
// _index, indice de la valeur dans le dataset
|
2016-04-19 15:08:59 +00:00
|
|
|
};
|
|
|
|
|
2016-05-23 09:10:24 +00:00
|
|
|
subject = 273;
|
2016-04-19 15:08:59 +00:00
|
|
|
|
|
|
|
|
2016-05-23 10:07:18 +00:00
|
|
|
var charts = ['sexe', 'direction', 'type', 'ages', 'relations'];
|
|
|
|
var types = ['doughnut', 'doughnut', 'doughnut', 'bar', 'bar'];
|
2016-05-23 09:10:24 +00:00
|
|
|
var canvas = []; // Contiendra les canvas
|
|
|
|
var instances = []; // Contiendra les charts
|
|
|
|
|
|
|
|
/* [1] On crée les conteneurs
|
2016-04-15 10:10:38 +00:00
|
|
|
=========================================================*/
|
2016-05-23 09:10:24 +00:00
|
|
|
for( var c in charts ){
|
|
|
|
canvas[c] = document.createElement('canvas');
|
|
|
|
canvas[c].id = charts[c];
|
2016-05-23 10:07:18 +00:00
|
|
|
canvas[c].width = 400;
|
|
|
|
canvas[c].height = 400;
|
2016-05-23 09:10:24 +00:00
|
|
|
subPhone.appendChild( canvas[c] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Pour chaque graphique, on récupère les données et on les affiche
|
|
|
|
=========================================================*/
|
|
|
|
for( var c = 0 ; c < charts.length ; c++ ){
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) On rédige la requête */
|
|
|
|
var request = {
|
|
|
|
path: 'chart/'+charts[c],
|
|
|
|
subject: subject
|
|
|
|
};
|
|
|
|
|
2016-05-23 10:07:18 +00:00
|
|
|
|
2016-05-23 09:10:24 +00:00
|
|
|
/* (2) On lance la requête */
|
|
|
|
api.send(request, function(response, args){
|
2016-05-23 10:07:18 +00:00
|
|
|
console.log(api.buffer);
|
2016-05-23 09:10:24 +00:00
|
|
|
// On récupère @c dans le scope du handler
|
|
|
|
var c = args[0];
|
|
|
|
|
|
|
|
/* (3) Si erreur, on quitte */
|
|
|
|
if( response.ModuleError != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* [2] On construit les données
|
|
|
|
=========================================================*/
|
|
|
|
var data = {
|
|
|
|
labels: response.labels,
|
|
|
|
datasets: response.datasets
|
|
|
|
};
|
|
|
|
|
2016-05-23 10:07:18 +00:00
|
|
|
Chart.defaults.global.title.text = charts[c].charAt(0).toUpperCase()+charts[c].slice(1).toLowerCase();
|
2016-05-23 09:10:24 +00:00
|
|
|
/* [3] On construit notre graphique
|
|
|
|
=========================================================*/
|
|
|
|
instances[c] = new Chart(canvas[c], {
|
|
|
|
type: types[c],
|
|
|
|
animation: { animateScale: true },
|
2016-05-23 10:07:18 +00:00
|
|
|
data: data,
|
|
|
|
options: {
|
|
|
|
scaleShowLabels: false
|
|
|
|
}
|
2016-05-23 09:10:24 +00:00
|
|
|
});
|
2016-04-15 16:40:15 +00:00
|
|
|
|
2016-05-23 09:10:24 +00:00
|
|
|
}, null, c);
|
2016-04-15 16:40:15 +00:00
|
|
|
|
|
|
|
|
2016-04-15 10:10:38 +00:00
|
|
|
|
2016-05-23 09:10:24 +00:00
|
|
|
}
|