Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/09/2013, 07:20
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Estadisticas en jquery

Hola, tengo este código para sacar estadísticas. Pero no se como se hace el data[]. No me saca las variables ($mes, $avisos ):

Código Javascript:
Ver original
  1. series: [{
  2.         type: 'line',                
  3.         name: 'Meses',
  4.         data: [<? echo $mes; ?>]                
  5.          },{
  6.         name: 'Avisos',
  7.         data: [<? echo $avisos; ?>]    
  8.          }
  9. ]


Código Javascript:
Ver original
  1. <?php
  2. $conexion=mysql_connect ("localhost","","");
  3. mysql_select_db ("Avisoswed",$conexion);
  4.     $query = mysql_query("SELECT MONTH( realizacion ) AS mes, COUNT( 1 ) AS avisos
  5. FROM avisos
  6. WHERE realizacion
  7. BETWEEN '2012-01-01'
  8. AND '2012-12-31'
  9. GROUP BY MONTH( realizacion )
  10. ORDER BY MONTH( realizacion )");
  11.  
  12. if (mysql_num_rows($query)>0 ) {  
  13.  
  14.   $datos = array();
  15.      
  16.     while($row = mysql_fetch_array($query))
  17.     {
  18.          
  19.         $datos[] = array(
  20.          
  21.             'mes' => $row['0'],
  22.             'avisos' => $row['1']
  23.    
  24.         );
  25.     }
  26.     // convertimos el array de datos a formato json
  27.     json_encode($datos);
  28. }
  29. ?>
  30.  
  31.  
  32. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  33. <html>
  34.     <head>
  35.      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  36.        <title>Estadisticas con Jquery | Jquery Easy</title>
  37.         <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
  38.         <script type="text/javascript" src="js/highcharts.js"></script>
  39.         <!-- Este archivo es para darle un estilo (Este archivo es Opcional) -->
  40.         <script type="text/javascript" src="js/themes/grid.js"></script>
  41.         <!-- Este archivo es para poder exportar losd atos que obtengamos -->
  42.         <script type="text/javascript" src="js/modules/exporting.js"></script>
  43.     <script type="text/javascript">
  44.        
  45.             var chart;
  46.             $(document).ready(function() {
  47.                 chart = new Highcharts.Chart({
  48.                     chart: {
  49.                         renderTo: 'container',
  50.                         plotBackgroundColor: null,
  51.                         plotBorderWidth: null,
  52.                         plotShadow: false
  53.                     },
  54.                     title: {
  55.                         text: 'Comparativa facturación avisos FG 2012-2013'
  56.                     },
  57.                     tooltip: {
  58.                         formatter: function() {
  59.                             return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
  60.                         }
  61.                     },
  62.                     plotOptions: {
  63.                         line: {
  64.                             allowPointSelect: true,
  65.                             cursor: 'pointer',
  66.                             dataLabels: {
  67.                                 enabled: false
  68.                             },
  69.                             showInLegend: true
  70.                         }
  71.                     },
  72.                    
  73.                      series: [{
  74.         type: 'line',                
  75.         name: 'Meses',
  76.         data: [<? echo $mes; ?>]               
  77.          },{
  78.         name: 'Avisos',
  79.         data: [<? echo $avisos; ?>]    
  80.          }
  81. ]
  82.                
  83.                 });
  84.             });
  85.         </script>
  86. <style type="text/css">
  87.            h4{ font-family:Arial, Helvetica, sans-serif;
  88.            color:#630;}
  89.            .cabecera{
  90.                 background: #4A3C31;
  91.                 border-bottom: 5px solid #69AD3C;
  92.                 margin:-8px 0 0 -8px;
  93.                 width: 100%;
  94.             }
  95.            .cabecera img{
  96.                 margin:40px 0 0 30px;
  97.             }
  98.  
  99. </style>   
  100.     </head>
  101. <body>
  102. <div class="cabecera"><a href="http://jqueryeasy.com/"><img src="http://www.jqueryeasy.com/application/views/templates/colorvoid/static/images/logo.gif" border="0" /></a></div>
  103.  
  104.    
  105.    
  106.    
  107.     <center><h4>Graficos Estadisticos con Jquery</h4></center>
  108.    
  109.     <div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
  110.        
  111.        
  112. </body>
  113. </html>

EDITO:

Lo he intentado así pero no sale, estoy atascado en que no se como pasar la respuesta del array json a esta linea:

Código Javascript:
Ver original
  1. $serie1 = array( 'name' => 'Avisos' , 'data' => array($row['1']) ) ;

Código Javascript:
Ver original
  1. $datos[] = array(
  2.        
  3.             array('avisos'  => $row['1'])
  4.    
  5.         );
  6.     }
  7.    
  8.     // convertimos el array de datos a formato json
  9.     echo json_encode($datos);
  10. }
  11.  
  12.  
  13. $serie1 = array( 'name' => 'Avisos' , 'data' => array($row['1']) ) ;
  14.  
  15. $array = array();
  16. array_push( $array, $serie1);

Código Javascript:
Ver original
  1. <?php
  2. $conexion=mysql_connect ("localhost","","");
  3. mysql_select_db ("Avisoswed",$conexion);
  4.     $query = mysql_query("SELECT MONTH( realizacion ) AS mes, COUNT( 1 ) AS avisos
  5. FROM avisos
  6. WHERE realizacion
  7. BETWEEN '2012-01-01'
  8. AND '2012-12-31'
  9. GROUP BY MONTH( realizacion )
  10. ORDER BY MONTH( realizacion )");
  11.  
  12. if (mysql_num_rows($query)>0 ) {  
  13.  
  14. $datos = array();
  15.      
  16.     while($row = mysql_fetch_array($query))
  17.     {
  18.  
  19.  
  20.  
  21.         $datos[] = array(
  22.        
  23.             array('avisos'  => $row['1'])
  24.    
  25.         );
  26.     }
  27.    
  28.     // convertimos el array de datos a formato json
  29.     echo json_encode($datos);
  30. }
  31.  
  32.  
  33. $serie1 = array( 'name' => 'Avisos' , 'data' => array($row['1']) ) ;
  34.  
  35. $array = array();
  36. array_push( $array, $serie1);
  37.  
  38. ?>
  39.  
  40.  
  41. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  42.     "http://www.w3.org/TR/html4/loose.dtd">
  43. <html>
  44.     <head>
  45.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  46.         <title>Ejemplo Estadistica</title>
  47.         <script src="jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
  48.         <script src="jquery/estadisticas/highcharts.js" type="text/javascript"></script>
  49.         <script src="jquery/estadisticas/modules/exporting.js" type="text/javascript"></script>
  50.         *
  51.         <script type="text/javascript">                        
  52.             $(function () {
  53.                 var datos =  <?php echo json_encode( $array) ?>;
  54.                 var chart;
  55.                 $(document).ready(function() {
  56.                     chart = new Highcharts.Chart({
  57.                         chart: {
  58.                             renderTo: 'container',
  59.                             type: 'line',
  60.                             marginRight: 130,
  61.                             marginBottom: 25
  62.                         },
  63.                         title: {
  64.                             text: 'Monthly Average Temperature',
  65.                             x: -20 //center
  66.                         },
  67.                         subtitle: {
  68.                             text: 'Source: WorldClimate.com',
  69.                             x: -20
  70.                         },
  71.                         xAxis: {
  72.                             categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  73.                                 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  74.                         },
  75.                         yAxis: {
  76.                             title: {
  77.                                 text: 'Nº Avisos'
  78.                             },
  79.                             plotLines: [{
  80.                                     value: 0,
  81.                                     width: 1,
  82.                                     color: '#808080'
  83.                                 }]
  84.                         },
  85.                         tooltip: {
  86.                             formatter: function() {
  87.                                 return '<b>'+ this.series.name +'</b><br/>'+
  88.                                     this.x +': '+ this.y +'°C';
  89.                             }
  90.                         },
  91.                         legend: {
  92.                             layout: 'vertical',
  93.                             align: 'right',
  94.                             verticalAlign: 'top',
  95.                             x: -10,
  96.                             y: 100,
  97.                             borderWidth: 0
  98.                         },
  99.                         series: datos
  100.                     });
  101.                 });
  102.             });
  103.             *
  104.         </script>
  105.     </head>
  106.     <body>
  107.         <div id="container" style="width: 100%; height: 400px"></div>
  108.     </body>
  109. </html>

Gracias y un saludo

Última edición por satjaen; 15/09/2013 a las 17:08