我想在高图饼图3D中显示最常用的类别,但它不起作用,json编码数组只接收一行数据。这是我的PHP代码:
$script1 = "SELECT categoria, COUNT(categoria) from entidade GROUP BY categoria ORDER BY COUNT(categoria) DESC";
$result9 = mysql_query($script1);
$data = array();
while ($row = mysql_fetch_array($result9))
{
$data[] = json_encode(array(array($row['categoria'], $row['COUNT(categoria)'])));
}
这是我的javaScript:
$(function () {
Highcharts.chart('container2', {
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45
}
},
title: {
text: 'Categoria de Crimes Mais Cometidos'
},
subtitle: {
text: ''
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45
}
},
series: [{
name: 'Quantidade:',
data:JSON.parse(<?php echo(json_encode($data));?>)
}]
请帮助我!
答案 0 :(得分:0)
如果你想拥有你之前评论过的所需数组格式,我认为你需要像这样分配数组:
$data = array();
$iIndexCounter = 0;
while ($row = mysql_fetch_array($result9)) {
$data[$iIndexCounter][] = $row['categoria'];
$data[$iIndexCounter][] = $row['COUNT(categoria)']
iIndexCounter++;
// e.g : $data[0][0] = Crab Vermecilli; || $data[0][1] = 0;
}
echo json_encode($aData); //[["Crab Vermecilli",0], ["Salted Egg Yolk Crab",0]]
$iIndexCounter
将成为包含这两个值的数组索引(例如categoria和COUNT(categoria))
希望这有助于您的情况。