Ver Mensaje Individual
  #4 (permalink)  
Antiguo 27/03/2014, 05:47
Avatar de evolutionrgm
evolutionrgm
 
Fecha de Ingreso: mayo-2011
Mensajes: 108
Antigüedad: 13 años
Puntos: 5
Respuesta: Reportes Graficos con PHP

Yo utilice unos graficos de google API
te dejare un ejemplo

Código PHP:
Ver original
  1. <?php
  2. $con=mysql_connect("localhost","root","pass") or die("Failed to connect with database!!!!");
  3. mysql_select_db("BD", $con);
  4. mysql_query("SET NAMES 'utf8'");
  5. // The Chart table contains two fields: weekly_task and percentage
  6. // This example will display a pie chart. If you need other charts such as a Bar chart, you will need to modify the code a little to make it work with bar chart and other charts
  7. $sth = mysql_query("SELECT  alta.ccosto,producto.nombre,COUNT(alta.producto)as cantidad
  8.     from alta
  9. INNER JOIN producto
  10. ON alta.producto=producto.cod_producto
  11. INNER JOIN
  12. centro_costo
  13. on
  14. alta.ccosto=centro_costo.idccosto GROUP BY alta.producto;");
  15.  
  16.  
  17.  
  18. $rows = array();
  19. //flag is not needed
  20. $flag = true;
  21. $table = array();
  22. $table['cols'] = array(
  23.  
  24.     // Labels for your chart, these represent the column titles
  25.     // Note that one column is in "string" format and another one is in "number" format as pie chart only required "numbers" for calculating percentage and string will be used for column title
  26.     array('label' => 'nombre', 'type' => 'string'),
  27.     array('label' => 'cantidad', 'type' => 'number')
  28.  
  29. );
  30.  
  31. $rows = array();
  32. while($r = mysql_fetch_assoc($sth)) {
  33.     $temp = array();
  34.     // the following line will be used to slice the Pie chart
  35.     $temp[] = array('v' => (string) $r['nombre']);
  36.  
  37.     // Values of each slice
  38.     $temp[] = array('v' => (int) $r['cantidad']);
  39.     $rows[] = array('c' => $temp);
  40. }
  41.  
  42. $table['rows'] = $rows;
  43. $jsonTable = json_encode($table);
  44. //echo $jsonTable;
  45. ?>
  46.  
  47. <html>
  48.   <head>
  49.     <!--Load the Ajax API-->
  50.     <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  51.     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  52.     <script type="text/javascript">
  53.  
  54.     // Load the Visualization API and the piechart package.
  55.     google.load('visualization', '1', {'packages':['corechart']});
  56.  
  57.     // Set a callback to run when the Google Visualization API is loaded.
  58.     google.setOnLoadCallback(drawChart);
  59.  
  60.     function drawChart() {
  61.  
  62.       // Create our data table out of JSON data loaded from server.
  63.       var data = new google.visualization.DataTable(<?=$jsonTable?>);
  64.       var options = {
  65.            title: 'Cantidad x Productos',
  66.           is3D: 'true',
  67.           width: 800,
  68.           height: 600
  69.         };
  70.       // Instantiate and draw our chart, passing in some options.
  71.       // Do not forget to check your div ID
  72.       var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  73.       chart.draw(data, options);
  74.     }
  75.     </script>
  76.   </head>
  77.  
  78.   <body>
  79.     <!--this is the div that will hold the pie chart-->
  80.     <div id="chart_div"></div>
  81.   </body>
  82. </html>