Nombre de séries variables
Bonjour à tous,
Je souhaite faire un graphique HighChart avec des données provenant d'une bdd, mais avec un nombre de série variable, et c'est là que je bloque.
Voici le data_line.php:
Code:
1 2 3 4 5 6 7 8
| while($r = mysql_fetch_array($query)) {
while($r1 = mysql_fetch_array($query1)) {
$series['data'][] = $r1['Indice'];
}
$result = array();
array_push($result,$series);
}
print json_encode($result, JSON_NUMERIC_CHECK); |
et le js:
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 54 55
| $(document).ready(function() {
var options = {
chart: {
renderTo: 'containerLine',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: null
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Euros'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 50,
borderWidth: 0
},
series: []
}
// C'est ici qu'est le problème :
$.getJSON("data_line.php", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
chart = new Highcharts.Chart(options);
});
}); |
Comment faire dans cette dernière partie, la récupération du Json, pour ne déclarer que le nombre de séries nécessaires?
Merci de votre aide