I'm trying to make graphs in PHP and MySQL using jQuery, specifically with Highcharts library, I have managed to make the chart with data from MySQL database, but these data show some data if they are in the databases but not others, for example, a query that yields 10 results 5 are good, but the other five did not, I have done some research on the web and I understand it is due to a problem when I pass the result of my query in MySQL by json_encode, I hope some of you can tell me because I have this error or if I'm misusing the JSON, thank you very much. Code: index.php
<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
<?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);
?>
The error is for example when I want to show 10 row of the database in the graph, it show me the results of this form:
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"
The problem is that in the graph (pie) displays correct data but not others, it is as if some records or tubiese skipped a limit of 5 registrros, not I do not know where I'm wrong. :(
thanks for helping :)