highcharts tables

0

Sorry I wanted to know how to spend a sum of hours thrown at me this query

SELECT form_matto.id_tecnico, SEC_TO_TIME(SUM(TIME_TO_SEC(tiempom))) as cuantas, 
tecnico.nombre FROM form_matto, tecnico where form_matto.id_tecnico in ('1','2','3','4') 
AND form_matto.id_tecnico = tecnico.id_tecnico 
AND (fecha >= '2018-01-01' AND fecha <= '2018-01-02' ) 
GROUP BY id_tecnico

This gives me the total hours of the field ' tiempom ' of the table 'form_matto'.

What I want is to pass the result to a graph of highcharts , but the code that I have of the graph does not give me the result of the query.

This is my code of the highcharts

<?php 
include("funciones.php");
include("console.php");
include("dbconnect.php");
session_start();
//----------RECUPERACION DE DATOS ENVIANDOS DESDE EL FORMULARIO------------

 $fechaIni= htmlspecialchars($_POST['fecha1'], ENT_QUOTES);
 $fechaFin= htmlspecialchars($_POST['fecha2'], ENT_QUOTES);
 //echo Console::log('Departamento', $Departamento);
 $dataArray;
 $i=0;
 $sql = $conn->prepare("SELECT form_matto.id_tecnico,  
 SEC_TO_TIME(SUM(TIME_TO_SEC(tiempom))) as cuantas, tecnico.nombre FROM  
 form_matto, tecnico where form_matto.id_tecnico in ('1','2','3','4') 
 AND form_matto.id_tecnico = tecnico.id_tecnico 
 AND (fecha >= ? AND fecha <= ? ) 
 GROUP BY id_tecnico");'

 $sql->bindParam(1,$fechaIni, PDO::PARAM_INT);
 $sql->bindParam(2,$fechaFin, PDO::PARAM_INT);
 $sql->execute();

 if ($sql->rowCount () > 0){
 while($rows=$sql->fetch(PDO::FETCH_ASSOC)){
 $no_registrosArray[$i]=$rows['cuantas'];
 $dataArray[$i] = "{ name:'".$rows['nombre']."',   
 y:".$rows['cuantas']."}";
  echo Console::log('ArrayNoRegistros', $dataArray[$i]);
  $i++;
}
?>

    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
           <div class="x_panel">
               
             <div class="x_content">
                  <div id="container" style="min-width: 310px; height: 500px; max-width: 800px; margin: 0 auto"></div>
                  <button type="button" class="btn btn-success" onclick="menu(605);">Regresar</button>

                </div>

              </div>
            </div>
          </div>
<script type="text/javascript">
 Highcharts.chart('container', {
 chart: {
    plotBackgroundColor: null,
    plotBorderWidth: null,
    plotShadow: false,
    type: 'pie'
},
title: {
    text: 'Porcentajes de  horas trabajadas de los tecnicos ?>'
},
tooltip: {
    //pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    pointFormat: '{series.name}: <b>{point.y}</b><br/>',


    /*
    tooltip:{
      formatter: function(){
        return 'No. de Reportes: '+this.y;
      }
    }
    */
},
plotOptions: {
    pie: {
        allowPointSelect: true,
        cursor: 'pointer',
        dataLabels: {
            enabled: true,
            format: '<b>{point.name}</b>: {point.percentage:.1f} %',
            style: {
                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
            }
        }
    }
},
 series: [{
    name: 'Reportes',
    colorByPoint: true,
    data: (function(){
      var datos = [];
      <?php
      for ($j=0; $j < count($dataArray); $j++) { 
      ?>
      datos.push(<?php echo $dataArray[$j];?>);
      <?php
      }
      ?>
      return datos;
    })()
}]
});

<?php

}else{
   echo"<script>alert('No hay suficientes datos para generar el gráfico') 
 </script>";
include '../modelo/formularioGrafica2.php';
}

?>
    
asked by Eddy Olvera 29.01.2018 в 18:40
source

1 answer

0

Look, try the following: you create a javascript variable var datosClient = <?= $dataArray?>; which is where the data you want to pass to the graph is. Then you create another javascript variable var datos = []; and you move through the elements of the datosClient and you create the array ex:

for(var i in datosClient){
datos.push(datosClient[i]);
}

then the coding of the graphic would be:

series: [{
        name: 'Reportes',
        colorByPoint: true,
        data: datos
    
answered by 29.01.2018 в 19:58