我的问题如下:
我有一个数据库,它为我提供了两组信息,如下图所示:
http://i.imgur.com/tlVtVTX.png
我不太清楚我的 PHP/JSON 或 SQL 是否是这里的问题。我知道我的 JSON 数据集应该有多个数据,例如:
[{"name":"Person1","data":[123123, etc, etc, etc]}
我的问题是它显示为:
[{"name":"Person1","data":[123123]}
[{"name":"Person1","data":[2345436]}
JSON(因隐私问题而更改名称和编号):
[{"name":"Person1","data":[123123]},{"name":"Person1","data":[123123]}
,{"name":"Person2","data":[123123]},{"name":"Person2","data":[123123]}
,{"name":"Person3","data":[123123]},{"name":"Person3","data":[123123]}
,{"name":"Person4","data":[123123]},{"name":"Person4","data":[123123]}]
SQL(也改变了,应该是相同的查询):
$SQL = "SELECT ISNULL(USERNAME) AS Accountmanagers, xMonth AS xMonth, ROUND(SUM(report.[FATDOLLARS(EUR)]), 0) AS COGS
FROM SecretDB
WHERE xYear = '2013'
GROUP BY ISNULL(USERNAME), xMonth
ORDER BY ISNULL(USERNAME), xMonth
我的查询如下所示:
http://i.imgur.com/q4QCsRF.png
这是我用于 JSON 数据的 php:
while( $row = sqlsrv_fetch_array( $somevariablehere, SQLSRV_FETCH_ASSOC) )
{
$name = $row['Accountmanagers'];
$categories = array($row['xMonth']);
$data = array($row['COGS']);
$arr[] = array('name' => $name, 'data' => $data);
}
$arr = json_encode($arr, JSON_NUMERIC_CHECK);
echo $arr;
HighChart(“系列:json”替换为虚拟数据):
<script>
$(function () {
var chart3;
$(document).ready(function() {
// $.getJSON("account.php", function(json) {
chart3 = new Highcharts.Chart({
chart: {
renderTo: 'accountmanagers',
type: 'column'
},
title: {
text: '2012'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'],
title: { text: 'Month'}
},
yAxis: {
min: 0,
title: {
text: 'Revenue'
}
},
legend: {
layout: 'vertical',
backgroundColor: '#FFFFFF',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 70,
floating: true,
shadow: true
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y +'€';
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{"name":"Person1","data":[12528]},{"name":"Person1","data":[2658]},{"name":"Person2","data":[27368]},{"name":"Person2","data":[30793]},{"name":"Person3","data":[64987]},{"name":"Person3","data":[21582]},{"name":"Person4","data":[53735]},{"name":"Person4","data":[14810]}]
});
// });
});
});
</script>
我不知道您是否需要更多信息,如果需要,请告诉我。
我想组合“人员”或 Accountmanager 值,当然要在几个月内将它们分散,而不是为每个数据创建新系列。
提前致谢 :-)