Toto je základní rámec, který budete potřebovat, aby to fungovalo:
/*
* $normal is an array of (edad => peso) key/value pairs
* $desnutricion is an array of (edad => peso) key/value pairs
* $desnutricionSevera is an array of (edad => peso) key/value pairs
*
* you can hard-code these or pull them from a database, whatever works for you
*/
$sql = $conn->prepare("SELECT edad, peso FROM ESTATURA WHERE <criteria to select baby>");
$sql->execute();
$data = array(array('Meses', $apellido, 'Normal', 'Desnutricion', 'Desnutricion Severa'));
while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
$edad = $row['edad'];
// use (int) to parse the value as an integer
// or (float) to parse the value as a floating point number
// use whichever is appropriate
$edad = (int) preg_replace('/\D/', '', $edad);
$peso = $row['peso'];
$peso = (float) $peso;
$data[] = array($edad, $peso, $normal[$edad], $desnutricion[$edad], $desnutricionSevera[$edad]);
}
Poté ve vašem javascriptu:
function drawChart() {
var data = google.visualization.arrayToDataTable(<?php echo json_encode($data); ?>);
// sort the data by "Meses" to make sure it is in the right order
data.sort(0);
var options = {
title: 'Grafica de Crecimiento de niñas de 0 a 24 meses',
hAxis: {
title: 'Meses',
titleTextStyle: {color: '#333'}
},
vAxis: {
minValue: 0
},
series: {
0: {
// series options for this babys weight
type: 'line'
},
1: {
// series options for normal weight
type: 'area'
},
2: {
// series options for desnutricion
type: 'area'
},
3: {
// series options for desnutricion severa
type: 'area'
}
}
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
Vyzkoušejte to a zjistěte, zda to pro vás funguje.