Bonjour à tous,

J'ai un "petit" souci dans mon code, je pense que c'est tout bête, mais je passe à côté.
Le code fonctionne nickel lorsque je ne traite qu'un type, mais dés lors que j'essaye de le paramétrer pour traiter les 2 autres types, çe ne fonctionne plus.

Si je n'active que la partie rouge ou que la partie verte ou que la partie bleue, ça fonctionne, mais dés que j'en mets 2 ou 3, ça merdouille.

Merci d'avance pour voir ce que je n'arrive pas à voir

Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
/*----------------------------------------------------------------------------------------------*/		
/* Graph TRAFIC JOURNALIER                                                                      */		
/*----------------------------------------------------------------------------------------------*/		
	// Requête au serveur
	Annee = P_date.slice(0,4);

	P_Pltf = "LFPO";
	var deferred = $.get("./scripts/PHP/TraficJournalier.php?date=".concat(P_date)+"&pltf=".concat(P_Pltf));
	// Retour du serveur (traitement des données JSON)
	deferred.done(function(jsonData) {
		var update = false;
		if (jsonData[0].length > 0) {
			update = true;
			if ($("#LIG_TJ_LFPO").children().length == 0) {
//					addHTML("lfob", ["lfob_hg"], ["12"]); // on se place dans le div row ID="lfob", on crée une div lfob_hg col-md-12
				addHTML("LIG_TJ_LFPO", ["lfpo_tj"], ["12"]); // Graph de gauche=LFPB / Graph de droite=LFOB
			}
			createGraph_TJ(P_Pltf, Annee, jsonData[0], jsonData[1], jsonData[2]);
		} else {
			$("#LIG_TJ_LFPO").empty();
		}
		
		if (update){
			$(".graph-loading").hide();
			$("#btn-save-pdf").attr("disabled", false);
			$("#div-info").children('.message-p-info').html('');
			$("#div-info").children('.icon-p-info').html('');
		} else {
			$(".graph-loading").hide();
			$("#div-info").children('.message-p-info').html('<strong>Certaines données sont indisponibles...</strong>');
			$("#div-info").children('.icon-p-info').html('<i class="fa fa-exclamation-triangle fa-lg"></i>');
		}
	});
	
	P_Pltf = "LFPG";
	var deferred = $.get("./scripts/PHP/TraficJournalier.php?date=".concat(P_date)+"&pltf=".concat(P_Pltf));
	// Retour du serveur (traitement des données JSON)
	deferred.done(function(jsonData) {
		var update = false;
		if (jsonData[0].length > 0) {
			update = true;
			if ($("#LIG_TJ_LFPG").children().length == 0) {
				addHTML("LIG_TJ_LFPG", ["lfpg_tj"], ["12"]); // Graph de gauche=LFPB / Graph de droite=LFOB
			}
			createGraph_TJ(P_Pltf, Annee, jsonData[0], jsonData[1], jsonData[2]);
		} else {
			$("#LIG_TJ_LFPG").empty();
		}
		
		if (update){
			$(".graph-loading").hide();
			$("#btn-save-pdf").attr("disabled", false);
			$("#div-info").children('.message-p-info').html('');
			$("#div-info").children('.icon-p-info').html('');
		} else {
			$(".graph-loading").hide();
			$("#div-info").children('.message-p-info').html('<strong>Certaines données sont indisponibles...</strong>');
			$("#div-info").children('.icon-p-info').html('<i class="fa fa-exclamation-triangle fa-lg"></i>');
		}
	});
	
//		P_Pltf = "LFPB";
//		var deferred = $.get("./scripts/PHP/TraficJournalier.php?date=".concat(P_date)+"&pltf=".concat(P_Pltf));
//		// Retour du serveur (traitement des données JSON)
//		deferred.done(function(jsonData) {
//			var update = false;
//			if (jsonData[0].length > 0) {
//				update = true;
//				if ($("#LIG_TJ_LFPB").children().length == 0) {
////					addHTML("lfob", ["lfob_hg"], ["12"]); // on se place dans le div row ID="lfob", on crée une div lfob_hg col-md-12
//					addHTML("LIG_TJ_LFPB", ["lfpb_tj"], ["12"]); // Graph de gauche=LFPB / Graph de droite=LFOB
//				}
//				createGraph_TJ(P_Pltf, Annee, jsonData[0], jsonData[1], jsonData[2]);
//			} else {
//				$("#LIG_TJ_LFPB").empty();
//			}
//			
//			if (update){
//				$(".graph-loading").hide();
//				$("#btn-save-pdf").attr("disabled", false);
//				$("#div-info").children('.message-p-info').html('');
//				$("#div-info").children('.icon-p-info').html('');
//			} else {
//				$(".graph-loading").hide();
//				$("#div-info").children('.message-p-info').html('<strong>Certaines données sont indisponibles...</strong>');
//				$("#div-info").children('.icon-p-info').html('<i class="fa fa-exclamation-triangle fa-lg"></i>');
//			}
//		});
//		
}

/*----------------------------------------------------------------------------------------------*/		
/* VARIABLES GLOBALES CONSTANTES POUR LES GRAPHES                                               */		
/*----------------------------------------------------------------------------------------------*/		

var WPaddingTexte_xAxis = 30;
var WPaddingTexte_yAxis = 35;
var P_AxeTextSize = 15;
var P_TextColor = "#5d6d7e"; // gris légèrement foncé
var P_CoulFond = "#ffffff"; // blanc
var P_Colors = ["#FE0000"]; // rouge
var P_TAB_Colors = ['#ff0000', '#0000FF', '#008000']; // Couleur des courbes => ROUGE, BLEU, VERT

var P_Debut = {
	textStyle: {
		fontFamily: 'sans-serif'
	},
	animation: true,
};
var P_Grid = {
	show: false,							// Whether to show the grid in rectangular coordinate
	top: 50,								// Distance between grid component and the top side of the container
	bottom: 80,								// Distance between grid component and the bottom side of the container
	left: 150,								// Distance between grid component and the left side of the container
	right: 30								// Distance between grid component and the right side of the container
};
var P_Legend = {
	show: true,
	type : 'plain',
	orient: 'vertical',
	borderColor: '#95a5a6',
	borderWidth: 2,
	borderRadius: 10,
	shadowColor: 'rgba(0, 0, 0, 0.5)',
	shadowBlur: 10,
	itemWidth: 25,
	itemHeight: 14,
	left: 3,
	top: 15
};
var P_Toolbox = {									// Cartouche en haut à droite
	show: true,
	padding: [5, 25, 0, 0],	// [haut, droit, bas, gauche]
	itemSize: 17,
	itemGap: 10,
	showTitle: true,		
	feature: {
		restore: {
			show: true,
			title: 'Rechargement'
		},
		magicType: {
			type: ['line', 'bar'],
			title: {
				line: 'Ligne',
				bar: 'Histo.'
			}
		},
	saveAsImage: {title:'Sauvegarde'}
	}
};
var P_XSplitArea = { 							// Permet de mettre un fond de couleurs différentes
	show: false,
	areaStyle:{
		color:['rgba(144,238,144,0.3)','rgba(135,200,250,0.3)']
	},
};
var P_XAxisLine = {
	lineStyle: {
		color: 'rgb(105,105,105)',
		width: 2,
		onZero: true,
	}
};
var P_YAxisLine = {
	lineStyle: {
		color: 'rgb(165,165,165)',
		width: 2
	}
};
var P_YAxisTick = {
	length: 3,
};
var P_YAxisLabel = { 							// Settings related to axis label
	color: 'rgb(070,070,070)'
};
var P_YSplitLine = {
	lineStyle:{
		width: 1,
		type: "dotted"
	}
};

/*----------------------------------------------------------------------------------------------*/		
/* Graph TRAFIC JOURNALIER - GRAND                                                              */		
/*----------------------------------------------------------------------------------------------*/		
function createGraph_TJ(P_Plateforme, P_Annee, jsonData_N, jsonData_N1, jsonData_N2){
	var i = 0,
		sepDate = " ", // Séparateur utilisé dans les dates lues dans la BDD.
		WAnneeN = parseInt(P_Annee),
		WAnneeN1 = P_Annee - 1,
		WAnneeN2 = P_Annee - 2,
		WJourN2 = 0,
		WJourN1 = 0,
		WJourN = 0,
		WMin = 0,
		WMax = 0,
		WDerNumJour = 0,
		QuadrillageVertical = [],
		DateMouv = [],
		MoisMouv_X = [],
		Jours_X = [],
		NbMouvN_Y = [],
		NbMouvN1_Y = [],
		NbMouvN2_Y = [];
	
	// Remplissage des tableaux
	if (jsonData_N2.length > 0)		
	{	
		i = 0;
		SerieChoisie = "";
		WMax = 0;
		WMin = parseInt(jsonData_N2[0][4]);
		while (i < jsonData_N2.length){
			var WNbMouv_N2 = parseInt(jsonData_N2[i][4]);
			WNbMouv_N2 = WNbMouv_N2 + parseInt(jsonData_N2[i+1][4]);
			WMax = MinMax(WNbMouv_N2, WMax, "MAX");
			WMin = MinMax(WNbMouv_N2, WMin, "MIN");
			NbMouvN2_Y.push(WNbMouv_N2);
			WJourN2 = WJourN2 + 1;
			i += 2; // Il faut avancer de 2 car il y a 1 ligne pour sens="A" et 1 ligne pour sens="D"
		}
		SerieChoisie = "N2";
	}
	if (jsonData_N1.length > 0)		
	{	
		i = 0;
		while (i < jsonData_N1.length){
			var WNbMouv_N1 = parseInt(jsonData_N1[i][4]);
			WNbMouv_N1 = WNbMouv_N1 + parseInt(jsonData_N1[i+1][4]);
			WMax = MinMax(WNbMouv_N1, WMax, "MAX");
			WMin = MinMax(WNbMouv_N1, WMin, "MIN");
			NbMouvN1_Y.push(WNbMouv_N1);
			WJourN1 = WJourN1 + 1;
			i += 2; // Il faut avancer de 2 car il y a 1 ligne pour sens="A" et 1 ligne pour sens="D"
		}
		if (jsonData_N1.length >= jsonData_N2.length)
		{
			SerieChoisie = "N1";
		}
	}
	if (jsonData_N.length > 0)		
	{	
		i = 0;
		while (i < jsonData_N.length){
			var WNbMouv_N = parseInt(jsonData_N[i][4]);
			WNbMouv_N = WNbMouv_N + parseInt(jsonData_N[i+1][4]);
			WMax = MinMax(WNbMouv_N, WMax, "MAX");
			WMin = MinMax(WNbMouv_N, WMin, "MIN");
			NbMouvN_Y.push(WNbMouv_N);
			WJourN = WJourN + 1;
			i += 2; // Il faut avancer de 2 car il y a 1 ligne pour sens="A" et 1 ligne pour sens="D"
		}
		if (jsonData_N.length >= jsonData_N1.length)
		{
			SerieChoisie = "N";
		}
	}

// Traitement pour l'axe des X
// Il faut déterminer quelle série va servir pour l'axe des X.
	if (SerieChoisie == "N")
	{
		WNbJourTot = jsonData_N.length;
	}
	if (SerieChoisie == "N1")
	{
		WNbJourTot = jsonData_N1.length;
	}
	if (SerieChoisie == "N2")
	{
		WNbJourTot = jsonData_N2.length;
	}
	i = 0;
	WNumJour = 0;
	while (i <= WNbJourTot - 1)
	{
		if (SerieChoisie == "N")
		{
			var WJour = jsonData_N[i][3].slice(8,10);
			var WMois = jsonData_N[i][3].slice(5,7);
			var WJourSemaine = JourEnLettres(jsonData_N[i][3]);
		}
		if (SerieChoisie == "N1")
		{
			var WJour = jsonData_N1[i][3].slice(8,10);
			var WMois = jsonData_N1[i][3].slice(5,7);
			var WJourSemaine = JourEnLettres(jsonData_N1[i][3]);
		}
		if (SerieChoisie == "N2")
		{
			var WJour = jsonData_N2[i][3].slice(8,10);
			var WMois = jsonData_N2[i][3].slice(5,7);
			var WJourSemaine = JourEnLettres(jsonData_N2[i][3]);
		}
		WMois = MoisEnLettres(WMois);
		QuadrillageVertical.push({
			xAxis: "01" + sepDate + WMois
		});
//			var WDateMouv = WJour + " " + WMois;// + " (Jour N° " + (parseInt(WNumJour) + 1) + ")"; 
		var WDateMouv = WJourSemaine + " " + WJour + " " + WMois;// + " (Jour N° " + (parseInt(WNumJour) + 1) + ")"; 
		Jours_X.push(WNumJour);
		DateMouv.push(WDateMouv);
		MoisMouv_X.push(WMois);
		WNumJour = WNumJour + 1;
		i=i+2;
	}

// Récupération du dernier jour de l'année N traité pour placer le DataZoom
	WDerNumJour = WJourN;
	WDebZoom = ((WDerNumJour * 100) / 365) - 25;
	WFinZoom = ((WDerNumJour * 100) / 365) + 15;
	if (WDebZoom < 0)
		{
			WDebZoom = 0; // 0%
			WFinZoom = 33; // 33%
		}

console.log(P_Plateforme);
	
	if (P_Plateforme == "LFPO")
		{
			var TJ_Chart_C1 = echarts.init(document.getElementById("lfpo_tj"));  //
			val = ($("#lfpo_tj").width() / 37);
			padding_array = [0, 0, 0, val];					// [haut, droit, bas, gauche]
			P_Titre = "Trafic Journalier LFPO";
		}
	if (P_Plateforme == "LFPG")
		{
			var TJ_Chart_C2 = echarts.init(document.getElementById("lfpg_tj"));  //
			val = ($("#lfpg_tj").width() / 37);
			padding_array = [0, 0, 0, val];					// [haut, droit, bas, gauche]
			P_Titre = "Trafic Journalier LFPG";
		}
	if (P_Plateforme == "LFPB")
		{
			var TJ_Chart_C3 = echarts.init(document.getElementById("lfpb_tj"));  //
			val = ($("#lfpb_tj").width() / 37);
			padding_array = [0, 0, 0, val];					// [haut, droit, bas, gauche]
			P_Titre = "Trafic Journalier LFPB";
		}

	var TJ_ChartOpt = {
		backgroundColor: P_CoulFond,
		color: P_TAB_Colors,
		
		P_Debut, // Début du paramètrage des graphique (police, animation, etc...)
		grid: P_Grid,
		legend: P_Legend,
		toolbox: P_Toolbox,
		
		title: {
			padding: [20, 5, 0, 5],					// Title space around content
			text: P_Titre,
			left: 'center'							// Distance between grid component and the left side of the container
		},
		xAxis: {				// The X axis in Cartesian (rect.) coordinate
			splitarea: P_XSplitArea,
			axisLine: P_XAxisLine,
			
			type: 'category',
			name: 'Mois',
			nameLocation: 'center',
			nameTextStyle: {
				padding: 5,							// Espace entre le libellé et la ligne de l'axe X
				fontWeight: 'bold',
				color: P_TextColor,
				fontSize : P_AxeTextSize
			},
			max: 'dataMax',
			position: 'bottom',
			boundaryGap: false, // IMPORTANT ! A Mettre à FALSE pour éviter le décalage
			// Affichage du trait repère
			axisTick: {
				/**
				* Pour affichage du trait repère sur l'axe X le 1er du mois
				* @param {object} index  - index du tableau de données traité
				* @param {object} valeur - valeur correspondante du tableau de données au format xx-mois
				*/
				interval: function (index, valeur) {
					// récup du jour
					valeur = DateMouv[index];// contient PAR EX dimanche 23 juillet
					var jour = valeur ? valeur.split(sepDate)[1] * 1 : 1;
					if (1 === jour) {
						return true;
					}
				}
			},
			// Affichage du label
			axisLabel: {
				/**
				* Pour affichage du label au milieu du mois, on met 15 pour simplifier
				* @param {object} index  - index du tableau de données traité
				* @param {object} valeur - valeur correspondante du tableau de données au format xx-mois
				* Nota : le return true entraine l'appel de la fonction de formatage
				*/
				align: "center",
				interval: function (index, valeur) {
				// récup du jour
					valeur = DateMouv[index];// contient PAR EX dimanche 23 juillet
					var jour = valeur ? valeur.split(sepDate)[1] * 1 : 15;
					if (15 === jour) {
						return true;
					}
				},
				formatter: function (index, valeur) {
					// récup du mois pour affichage
					valeur = DateMouv[index];// contient PAR EX dimanche 23 juillet
					return valeur ? valeur.split(sepDate)[2] : "";
				}
			},
			splitLine: {
				show: true, // True => quadrillage VERTICAL sur le graphe
				lineStyle: {
					color: "#CCC",
					type: "dotted",
					width: 1
				},
				interval: function (index, valeur) {
				// récup du jour
					  valeur = DateMouv[index];// contient PAR EX dimanche 23 juillet
					var jour = valeur ? valeur.split(sepDate)[1] * 1 : 1;
					if (1 === jour) {
					  return true;
					}
				}
			},				
			data: Jours_X
		},
		yAxis: {
			axisLine: P_YAxisLine,
			axisTick: P_YAxisTick,
			axisLabel: P_YAxisLabel,
			splitLine: P_YSplitLine,
			
			type: 'value',
			min: 'dataMin',//WMin,
			max: 'dataMax', //WMax'',
			name: 'Mouvements',
			nameLocation: 'center',
			nameRotate: 90,
			nameTextStyle: {
				padding: 35, // Décalage par rapport à l'axe des Y
				fontWeight: 'bold',
				color: P_TextColor,
				fontSize : P_AxeTextSize
			},
		},
		dataZoom: [{
			type: "slider",
			showDetail: true,
			showDataShadow: 'auto',
			realtime: true,
			rangeMode: "percent",      
			start: WDebZoom,      // the left is located at 10% - DEFAUT = 0
			end: WFinZoom,         // the right is located at 60% - DEFAUT = 33
			filterMode: "empty"
			},
			{
				type: "inside",
				filterMode: 'empty'
			}    
		],
		tooltip: {
			show: true,
			trigger: 'axis', 						// Triggered by axes.
			axisPointer: {
				type: 'line',
				label : {
					formatter: function (params) {
					return DateMouv[parseInt(params.value)]; // 
					}
				},
				lineStyle: {
					width: 1 						// Epaisseur de la ligne verticale
				}
			}
		},
		series : [
			{
				type: 'line',
				name: WAnneeN,					// Series name used for displaying in tooltip and filtering with legend
				symbolSize: 7,
				showSymbol: false,					// Whether to show symbol. It would be shown during tooltip hover
				lineStyle: {
					width: 2,
					type: 'solid' //'dotted' / 'dashed'
				},
				smooth: false,						// Permet de lisser ou non les courbes
				data: NbMouvN_Y
			},
			{
				type: 'line',
				name: WAnneeN1,					// Series name used for displaying in tooltip and filtering with legend
				symbolSize: 7,
				showSymbol: false,					// Whether to show symbol. It would be shown during tooltip hover
				lineStyle: {
					width: 1,
					type: 'solid' //'dotted' / 'dashed'
				},
				smooth: false,						// Permet de lisser ou non les courbes
				data: NbMouvN1_Y
			},
			{
				type: 'line',
				name: WAnneeN2,					// Series name used for displaying in tooltip and filtering with legend
				symbolSize: 7,
				showSymbol: false,					// Whether to show symbol. It would be shown during tooltip hover
				lineStyle: {
					width: 1,
					type: 'solid' //'dotted' / 'dashed'
				},
				smooth: false,						// Permet de lisser ou non les courbes
				data: NbMouvN2_Y
			}
		]
	};
	
	
	if (P_Plateforme == "LFPO")
		{
			TJ_Chart_C1.setOption(TJ_ChartOpt);
			var TJ_Chart_C1 = echarts.init(document.getElementById("lfpo_tj"));  //
		}
	if (P_Plateforme == "LFPG")
		{
			TJ_Chart_C2.setOption(TJ_ChartOpt);
			var TJ_Chart_C2 = echarts.init(document.getElementById("lfpg_tj"));  //
		}
	if (P_Plateforme == "LFPB")
		{
			TJ_Chart_C3.setOption(TJ_ChartOpt);
			var TJ_Chart_C3 = echarts.init(document.getElementById("lfpb_tj"));  //
		}
	
}