json_encode和highcharts [英] json_encode and highcharts
问题描述
我正在尝试使用jQuery(特别是Highcharts库)在PHP和MySQL中创建图形,我设法使用MySQL数据库中的数据制作了图表,但是如果这些数据在数据库中,则这些数据显示了一些数据,但没有显示其他数据. ,例如,产生10个结果5的查询是好的,但其他5个则不行,我已经在网络上进行了一些研究,并且我了解这是由于我通过json_encode在MySQL中传递查询结果而导致的问题,我希望你们中的一些人可以告诉我,因为我有此错误,或者如果我滥用JSON,非常感谢. 代码: index.php
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
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);
?>
例如,该错误是当我想在图表中显示数据库的10行时,它向我显示此表单的结果:
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"
问题在于,图表(pie)中显示的是正确数据,而其他数据则未显示,就好像某些记录或tubiese跳过了5个注册限制,不是我不知道我错了哪里. :(
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. :(
感谢您的帮助:)
推荐答案
首先,我将尝试为数组元素赋予一个值,而不是使用索引.给您的阵列键起一个名字.还要从编码中删除所有大写字母.我正在使用ipad,无法编写代码,但是如果您有任何疑问,请告诉我.
First of all I would try to give the array elements a value, instead of using the index. Give your array key a name. As well remove all the uppercase letters from your encode. I am on an ipad and unable to code, but let me know if you have questions.
这篇关于json_encode和highcharts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!