2013-04-09 4 views
2

jQuery를 사용하여 PHP 및 MySQL에서 그래프를 만들려고합니다. 특히 Highcharts 라이브러리에서 차트를 만들었지 만 MySQL 데이터베이스의 데이터로 차트를 만들었지 만 데이터베이스에있는 데이터는이 데이터에 표시됩니다. 예를 들어, 10 개의 결과를 얻는 쿼리가 좋지만 다른 다섯 개는 그렇지 않습니다. 웹에 대한 조사를 해본 결과 내 쿼리의 결과를 전달할 때 문제가 있다는 것을 이해합니다. json_encode에 의해 MySQL이, 나는 당신이 JSON을 오용하는 경우이 오류가 있거나 내가 대단히 감사합니다 때문에 당신이 말할 수 있기를 바랍니다. 코드 :json_encode 및 highcharts

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <title>Incidencias</title> 
    <script type="text/javascript" src="../js/jquery-1.7.1.min.js" ></script> 
    <script type="text/javascript" src="../js/highcharts.js" ></script> 
    <script type="text/javascript" src="../js/themes/grid.js"></script> 
    <script type="text/javascript" src="../js/export.js"></script> 
    <script type="text/javascript"> 
     var chart; 
      $(document).ready(function() { 
       var options = { 
        chart: { 
         renderTo: 'pieClientes', 
         defaultSeriesType: 'pie', 
         marginRight: 10, 
         marginBottom: 25 
        }, 
        title: { 
         text: 'top 10. Clientes con m\u00e1s incidencias', 
         x: -10 
        }, 
        subtitle: { 
         text: '', 
         x: -20 
        }, 
        tooltip: { 
         formatter: function() { 
          return '<b>'+ this.point.name +'</b>: <b>'+ this.y +' incidencias</b>'; 
         } 
        }, 
        legend: { 
         layout: 'vertical', 
         align: 'right', 
         verticalAlign: 'top', 
         x: -10, 
         y: 100, 
         borderWidth: 0 
        }, 

       series: [{ 
        type: 'pie', 
        name: 'Browser share', 
        data: [] 
       }] 
      } 

      $.getJSON("datosCliente.php", function(json) { 
       options.series[0].data = json; 
       chart = new Highcharts.Chart(options); 
      }); 
      }); 
    </script> 
</head> 
<body> 
    <div style="font-size: 12p; font-family: Calibri, Candara, Segoe, Segoe UI, Optima, Arial, sans-serif; align="left" > 
     <h1>Dashboard incidencias SCI</h1> 
    <div> 
    <div id="pieClientes" style="width: 770px; height: 450x; margin: 0"></div>    
</body> 
</html> 

datosCliente.php 내가 그래프 데이터베이스의 10 행을 표시 할 때 오류가, 예를 들면

<?php 
    include"../clases/conexion.php"; 
    $result = mysql_query("SELECT 
        clientes.cliente, 
        COUNT(incidencias.idIncidencia) AS nIncidencias 
        FROM incidencias 
        INNER JOIN clientes ON incidencias.idCliente = clientes.idCliente 
        GROUP BY incidencias.idCliente 
        ORDER BY nIncidencias DESC 
        LIMIT 0,10"); 
    $rows = array(); 
     while($r = mysql_fetch_array($result)) 
      { 
       $row[0] = $r[0]; 
       $row[1] = $r[1]; 
       array_push($rows,$row); 
      } 

    //print json_encode($rows, JSON_PRETTY_PRINT); 
    echo json_encode($rows, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT); 
    mysql_close($con); 
?> 

, 그것은 나에게 이것의 결과를 보여 의 index.php 형태 :

 1st. row-> show me "slice" 
     2nd. row-> the registerok, 
     3th. row-> show me "slice" 
     4. row-> the registerok, 
     5. row-> the registerok, 
     6.row-> show me "slice" 
    7.row->the registerok, 
    8.row-> show me "slice" 
    9.row->the registerok, 
    10.row-> show me "slice" 

문제는 어떤 기록이나 tubiese 5 개로 제한 생략 것처럼 그래프 (파이) 디스플레이 올바른 데이터가 아닌 다른 사람,이 있다는 레지스트라, 내가 어디가 잘못 됐는지 모르겠다. :(나는 배열 요소에 값을 제공하기 위해 노력하는 모든의 :

+0

무엇이 오류입니까? – Phil

+0

데이터/JSON의 모습은 어떻습니까? x 오름차순으로 데이터를 정렬 했습니까? –

답변

0

첫째을 돕는 대신 인덱스를 사용

감사합니다. 배열 키에 이름을 지정하십시오. 또한 인코딩에서 대문자를 모두 제거하십시오. 나는 ipad에 코드를 작성할 수 없지만 질문이 있으면 알려주십시오.