Foros del Web » Programando para Internet » PHP »

Google api chart

Estas en el tema de Google api chart en el foro de PHP en Foros del Web. Al fin logre entender la api de google para hacer gráficas... El problemas es que puedo leer el array si escribo los meses de uno ...
  #1 (permalink)  
Antiguo 18/08/2014, 17:26
Avatar de odek  
Fecha de Ingreso: julio-2011
Ubicación: México
Mensajes: 55
Antigüedad: 12 años, 9 meses
Puntos: 1
Google api chart

Al fin logre entender la api de google para hacer gráficas...

El problemas es que puedo leer el array si escribo los meses de uno en uno, pero quiero hacerlo por fechas. Digamos del 2014-09-01 al 2014-31-12.

Pueden ayudarme, porfavor a mejorar el código.

Aqui esta lo que llevo.


Código HTML:
Ver original
  1. <?php
  2.     $conexion = mysqli_connect("localhost","root","root","grafica");
  3.    
  4.     $meses = array('','Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sept','Oct','Nov','Dic');
  5.     for($x=1;$x<=12;$x=$x+1){
  6.         $dinero[$x]=0;     
  7.     }
  8.    
  9.     $anno=date('Y');
  10.    
  11.     $sql="SELECT * FROM valores";
  12.     $res=mysqli_query($conexion,$sql);
  13.     while($row=mysqli_fetch_array($res)){
  14.         $y=date("Y", strtotime($row['fecha']));
  15.        
  16.         $mes=(int)date("m", strtotime($row['fecha']));
  17.        
  18.         if($y==$anno){
  19.             $dinero[$mes]=$dinero[$mes]+$row['valor'];
  20.         }
  21.     }
  22. ?>
  23.  
  24. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  25. <html xmlns="http://www.w3.org/1999/xhtml">
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  27. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  28.     <script type="text/javascript">
  29.       google.load("visualization", "1", {packages:["corechart"]});
  30.       google.setOnLoadCallback(drawChart);
  31.       function drawChart() {
  32.         var data = google.visualization.arrayToDataTable([
  33.           ['Mes', 'Valores'],
  34.           <?php
  35.             for($x=1;$x<=12;$x=$x+1){  
  36.           ?>
  37.           ['<?php echo $meses[$x]; ?>',  <?php echo $dinero[$x] ?>],
  38.           <?php } ?>
  39.  
  40.         ]);
  41.  
  42.         var options = {
  43.           title: 'ESTATUS DE LA COMPAÑIA',
  44.           hAxis: {title: 'Grafica Reporte de Ingresos Anual', titleTextStyle: {color: 'red'}}
  45.         };
  46.  
  47.         var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
  48.         chart.draw(data, options);
  49.       }
  50.     </script>
  51. <title>Grafica SoftUnicorn</title>
  52. </head>
  53.  
  54.     <div id="chart_div" style="width: 98%; height: 500px;"></div>
  55. </body>
  56. </html>
__________________
Mi life in pixel -_-
  #2 (permalink)  
Antiguo 19/08/2014, 09:19
 
Fecha de Ingreso: agosto-2013
Ubicación: Guatemala
Mensajes: 137
Antigüedad: 10 años, 8 meses
Puntos: 4
Respuesta: Google api chart

entonces tu problema no está en la api sino en la consulta la cual debe ser asi

Código MySQL:
Ver original
  1. SELECT * FROM valores WHERE fecha BETWEEN '2014-01-09' AND '2014-12-31'

Etiquetas: api, chart, fecha, google, html, mysql, select, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:26.