Google API Charts con PHP
Escrito por J.F. el Domingo, 23 de Diciembre del 2007 a las 13:20
Un código de ejemplo para usar Google API Charts con PHP. Simplemente introducimos los datos en un array, creamos una url codificada y lo metemos en la etiqueta img. Aquí está el código de ejemplo:
-
<?
-
-
// Here's an array containing some data to plot
-
-
// Here's where we call the chart, and return the encoded chart data
-
-
// And here's the function
-
-
function chart_data($values) {
-
-
// Port of JavaScript from http://code.google.com/apis/chart/
-
// http://james.cridland.net/code
-
-
// First, find the maximum value from the values given
-
-
-
// A list of encoding characters to help later, as per Google's example
-
$simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
-
-
$chartData = "s:";
-
for ($i = 0; $i <count($values); $i++) {
-
$currentValue = $values[$i];
-
-
if ($currentValue> -1) {
-
}
-
else {
-
$chartData.='_';
-
}
-
}
-
-
// Return the chart data - and let the Y axis to show the maximum value
-
return $chartData."&chxt=y&chxl=0:|0|".$maxValue;
-
}
-
-
?>
Vía: | Ribosomatic | Autor del tutorial
- Añadir este post a
- Del.icio.us -
- Meneame -
- Digg -
- Webeame
Entradas relacionadas
Deja un comentario
