2016-05-24 07:01:16 +00:00
|
|
|
var subPhone = $('section[data-sublink="phone"]');
|
|
|
|
subPhone.style.display = 'flex';
|
|
|
|
subPhone.style.flexWrap = 'wrap';
|
|
|
|
subPhone.style.justifyContent = 'space-around';
|
|
|
|
|
|
|
|
/* [0] Paramètres globaux
|
2016-04-19 15:08:59 +00:00
|
|
|
=========================================================*/
|
2016-05-24 07:01:16 +00:00
|
|
|
Chart.defaults.global.responsive = false;
|
2016-05-24 16:59:19 +00:00
|
|
|
Chart.defaults.global.title.display = false;
|
|
|
|
Chart.defaults.global.tooltips.footerFontSize = 0;
|
2016-05-24 07:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
Chart.defaults.global.onClick = function(e, c){
|
|
|
|
console.log(e); // MouseEvent
|
|
|
|
if( c[0] != null )
|
|
|
|
console.log(c[0]._datasetIndex, c[0]._index); // Chart data
|
|
|
|
|
|
|
|
// _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-24 07:01:16 +00:00
|
|
|
subject = 273;
|
|
|
|
|
|
|
|
|
|
|
|
var charts = ['sexe', 'direction', 'type', 'ages', 'relations'];
|
2016-05-24 16:59:19 +00:00
|
|
|
var types = ['pie', 'pie', 'pie', 'column', 'bar'];
|
2016-05-24 07:01:16 +00:00
|
|
|
var canvas = []; // Contiendra les canvas
|
|
|
|
var instances = []; // Contiendra les charts
|
|
|
|
|
|
|
|
/* [1] On crée les conteneurs
|
|
|
|
=========================================================*/
|
|
|
|
for( var c in charts ){
|
2016-05-24 16:59:19 +00:00
|
|
|
canvas[c] = document.createElement('div');
|
2016-05-24 07:01:16 +00:00
|
|
|
canvas[c].id = charts[c];
|
2016-05-24 16:59:19 +00:00
|
|
|
// canvas[c].width = canvas[c].height = ( types[c] == 'bar' ) ? 500 : 300;
|
|
|
|
canvas[c].style.width = canvas[c].style.height = ( types[c] == 'column' ) ? '40em' : '30em';
|
|
|
|
canvas[c].style.margin = '2em';
|
2016-05-24 07:01:16 +00:00
|
|
|
subPhone.appendChild( canvas[c] );
|
|
|
|
}
|
2016-04-19 15:08:59 +00:00
|
|
|
|
|
|
|
|
2016-05-24 07:01:16 +00:00
|
|
|
/* [2] Pour chaque graphique, on récupère les données et on les affiche
|
2016-04-15 10:10:38 +00:00
|
|
|
=========================================================*/
|
2016-05-24 07:01:16 +00:00
|
|
|
for( var c = 0 ; c < charts.length ; c++ ){
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) On rédige la requête */
|
|
|
|
var request = {
|
|
|
|
path: 'chart/'+charts[c],
|
|
|
|
subject: subject
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On lance la requête */
|
|
|
|
api.send(request, function(response, args){
|
|
|
|
console.log(api.buffer);
|
|
|
|
// 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-04-15 16:40:15 +00:00
|
|
|
|
2016-05-24 07:01:16 +00:00
|
|
|
/* [3] On construit notre graphique
|
|
|
|
=========================================================*/
|
2016-05-24 16:59:19 +00:00
|
|
|
/* (1) On définit les options */
|
|
|
|
var options = {
|
|
|
|
chart: { renderTo: canvas[c], defaultSeriesType: types[c] },
|
|
|
|
series: response.series,
|
|
|
|
plotOptions: {
|
|
|
|
pie: {
|
|
|
|
allowPointSelect: true,
|
|
|
|
cursor: 'pointer',
|
|
|
|
dataLabels: {
|
|
|
|
enabled: true,
|
|
|
|
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
|
|
|
|
style: {
|
|
|
|
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
allowPointSelect: true,
|
|
|
|
cursor: 'pointer'
|
|
|
|
}
|
2016-05-24 07:01:16 +00:00
|
|
|
}
|
2016-05-24 16:59:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// labels
|
|
|
|
if( response.xlabels != null )
|
|
|
|
options.xAxis = { categories: response.xlabels };
|
|
|
|
|
|
|
|
if( response.ylabels != null )
|
|
|
|
options.yAxis = { categories: response.ylabels };
|
|
|
|
|
|
|
|
// titre
|
|
|
|
if( response.title != null )
|
|
|
|
options.title = { text: response.title };
|
|
|
|
|
|
|
|
// pointFormat
|
|
|
|
if( response.pointFormat != null )
|
|
|
|
options.tooltip = { pointFormat: response.pointFormat };
|
|
|
|
|
|
|
|
/* (2) On crée le graphique */
|
|
|
|
instances[c] = new Highcharts.Chart(options);
|
|
|
|
|
2016-04-15 16:40:15 +00:00
|
|
|
|
2016-05-24 07:01:16 +00:00
|
|
|
}, null, c);
|
2016-04-15 16:40:15 +00:00
|
|
|
|
|
|
|
|
2016-04-15 10:10:38 +00:00
|
|
|
|
2016-05-24 07:01:16 +00:00
|
|
|
}
|