我在我的應用程序項目中使用了Morris圖表,以顯示有關銷售數量的一些詳細信息。 執行AJAX請求後,該圖表表示無序way.It不顯示銷售每個city.I數據要像本實施例中有靜態數據http://jsfiddle.net/marsi/LaJXP/1/具有動態數據的Morris圖表
var json = (function() {
var json = null;
$.ajax({
'async': false,
'global': false,
'url': 'sales.php',
'dataType': "json",
'success': function (data) {
json = data;
}
});
return json;
})
();
Morris.Area({
element: 'graph-area',
padding: 10,
behaveLikeLine: true,
gridEnabled: false,
gridLineColor: '#dddddd',
axes: true,
fillOpacity:.7,
data:json,
lineColors:['#ED5D5D','#D6D23A','#32D2C9'],
xkey: 'data',
ykeys:['cityname','total'],
labels: ['city','total'],
pointSize: 0,
lineWidth: 0,
hideHover: 'auto'
});
<div id="graph-area"></div>
從JSON文件結果顯示它們(sales.php)看起來像:
[{"cityname":"Modena","total":"810.82","data":"2014-02-05 16:55:52"},
{"cityname":"Bologna","total":"396.22","data":"2014-02-09 23:58:20"},
{"cityname":"Rimini","total":"380.00","data":"2014-02-10 10:36:12"},
{"cityname":"Bologna","total":"736.30","data":"2014-02-10 23:30:58"},
{"cityname":"Bologna","total":"0.00","data":"2014-02-12 23:41:52"},
{"cityname":"Modena","total":"0.00","data":"2014-02-13 15:21:17"}]
你的數據是錯誤的格式,你需要 「重塑」或「旋轉」它。您應該爲每個城市名稱分別填寫每個值。 – marbel