Ver Mensaje Individual
  #5 (permalink)  
Antiguo 01/04/2015, 09:48
todasontodas
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Graficas Con pChart con PHP y MySQL (no me importa otra libreria de grafic

Ok, os pongo el codigo completo por si tengo problemas a la hora de obtener la sentencia SQL o el GET.

Código PHP:
Ver original
  1. <html>
  2. <head>
  3. <title>Graficas</title>
  4. </head>
  5.  
  6. <body>
  7.  
  8. <?php
  9. $servicio=$_GET['servicio'];
  10. $fechainicio=$_GET['fechainicio'];
  11. $fechafinal=$_GET['fechafinal'];
  12.  
  13. // Me conecto a la base de datos
  14. mysql_connect("localhost","root","Redinsa2015");
  15.  
  16. if (!empty($_GET['button'])){
  17. // en caso de que se ha presionado el boton enviar, procesar el formulario
  18. $servicio=$_GET['servicio'];
  19. $fechainicio=$_GET['fechainicio'];
  20. $fechafinal=$_GET['fechafinal'];
  21.  
  22. /* Incluimos las clases */
  23. include("/var/www/graficas/pChart/class/pData.class.php");
  24. include("/var/www/graficas/pChart/class/pDraw.class.php");
  25. include("/var/www/graficas/pChart/class/pImage.class.php");
  26.  
  27. /* Creamos el objeto */
  28. $myData = new pData();
  29.  
  30. //conectamos
  31. mysql_connect("localhost","root","Redinsa2015");
  32. $sql2="select Fecha, Cantidad from $servicio where Fecha between '&fechainicio' and 'fechafinal'";
  33.  
  34. $resultado=mysql_query($sql2);
  35. while($row = mysql_fetch_array($resultado))
  36. {
  37.     $Fecha = $row["Fecha"];
  38.     $myData->addPoints($Fecha,"Fecha");
  39.  
  40.     $Cantidad = $row["Cantidad"];
  41.     $myData->addPoints($Cantidad,"Cantidad");
  42. }
  43.  
  44. $myData-> setSerieOnAxis("Cantidad", 0); //assigns the data to the frist axis
  45. $myData-> setAxisName(0, "Frecuencia (Hz)"); //adds the label to the first axis
  46. $myData-> setAxisPosition(1,AXIS_POSITION_LEFT); //moves the second axis to the far left
  47. $myData->setAbscissa("Fecha"); //sets the time data set as the x axis label
  48. $myPicture = new pImage(1100,300,$myData); /* Create a pChart object and associate your dataset */
  49. $myPicture->setFontProperties(array("FontName"=>"/var/www/graficas/pChart/fonts/pf_arma_five.ttf","FontSize"=>6)); /* Choose a nice font */
  50. $myPicture->setGraphArea(80,40,1000,200); /* Define the boundaries of the graph area */
  51. $Settings = array("R"=>250, "G"=>250, "B"=>250, "Dash"=>1, "DashR"=>0, "DashG"=>0, "DashB"=>0);
  52. $myPicture->drawScale(array("LabelRotation"=>320)); /* Draw the scale, keep everything automatic */
  53. /*The combination makes a cool looking graph*/
  54. $myPicture->drawPlotChart();
  55. $myPicture->drawLineChart();
  56. $myPicture->drawLegend(90,20); //adds the legend
  57. $myPicture->autoOutput(); /* Build the PNG file and send it to the web browser */
  58. }
  59. else
  60. {
  61. ?>
  62.  
  63. <form method="get" action="index.php">
  64. <table width="70%" border="0" align="center">
  65. <?php
  66.  
  67. print ("
  68. <input type=\"hidden\" name=\"paisant\" value=\"$paisant\">
  69. <input type=\"hidden\" name=\"cantonant\" value=\"$cantonant\">
  70.  
  71. <tr>
  72. <td><div align=\"right\"><strong>Servicio:</strong></div></td>
  73.  
  74. <td><select name=\"servicio\" onchange=\"submit();\">
  75. ");
  76. //Muestra el combobox de las provincias una vez que se haya elegido el país, no antes
  77. if (!isset($servicio)){
  78. print ("<option selected>Seleccione el servicio</option>");
  79. $servicio="0";
  80. }
  81. $sql="SHOW FULL TABLES FROM base";
  82. $res=mysql_query($sql);
  83.  
  84. while($fila=mysql_fetch_array($res)){
  85. print("<option value=\"$fila[Tables_in_base]\"");
  86. if ($fila[Tables_in_base] == $servicio) {
  87. print ("selected");
  88. }
  89. print(">$fila[Tables_in_base]</option>\n");
  90. }
  91. print("</select></td></tr>");
  92. print ("
  93.  
  94. <tr>
  95. <td><div align=\"right\"><strong>Fecha de inicio:</strong></div></td>
  96. <td><select name=\"fechainicio\" onchange=\"submit();\">
  97. ");
  98. print ("<option selected>Seleccione la fecha de inicio</option>");
  99.  
  100. //Muestra el combobox de las parroquias una vez que se haya elegido el canton, no antes
  101. if (!isset($fechainicio)){
  102. $fechainicio="0";
  103. }
  104. $sqlcan="select Fecha from $servicio where Tabla='$servicio'";
  105. $res=mysql_query($sqlcan);
  106.  
  107. while($fila=mysql_fetch_array($res)){
  108. print("<option value=\"$fila[Fecha]\"");
  109. if ($fila[Fecha] == $fechainicio) {
  110. print ("selected");
  111. }
  112. print(">$fila[Fecha]</option>\n");
  113. }
  114. print("</select></td></tr>");
  115.  
  116. print("
  117. <tr>
  118. <td><div align=\"right\"><strong>Fecha de final:</strong></div></td>
  119. <td><select name=\"fechafinal\">
  120. ");
  121.  
  122. print ("<option selected>Seleccione la fecha final</option>");
  123. if (!isset($fechafinal)){
  124.  
  125. $fechafinal="0";
  126. }
  127. $sqlparr="select Fecha from $servicio where Tabla='$servicio'";
  128. $resparr=mysql_query($sqlparr);
  129.  
  130. while($filaprov=mysql_fetch_array($resparr)){
  131. print("<option value=\"$filaprov[Fecha]\">$filaprov[Fecha]</option>");
  132. }
  133. print("
  134. </select>
  135. </td>
  136. </tr>
  137. ");
  138.  
  139. ?>
  140.  
  141. <tr>
  142. <td><div align="right"><input name="button" type="submit" value="Enviar"></div></td>
  143. <td><input name="reset" type="reset" value="Borrar"></td>
  144. </tr>
  145. </table>
  146.  
  147. </form>
  148.  
  149. <?php
  150. } // cierro if principal del boton enviar
  151.  
  152. ?>
  153. </body>
  154. </html>