0
即時嘗試從json數組創建一個chartist線圖形。PHP Json陣列數據與憲章
echo json_encode($json_data);
回報
[{"labels": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27],
"series":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,0,2,0,0]}]
我的jQuery
var url = "/appx/array.php"
var resp = jQuery.parseJSON(
jQuery.ajax({
url: url,
async: false,
dataType: 'json'
}).responseText
);
var data = resp; // here i dont know how to do
/*var data = labels: ['1', '2', '3','4'], series: [[1, 3, 7, 12]] original data*/
new Chartist.Line("#teamCompletedWidget .ct-chart", data,options);
系列必須是數組的數組
series[[1,2,3]]
我的PHP代碼
個for($i=1; $i<=date("d"); $i++){
$json_array['labels'][] = $i;
$json_array['series'][] = intval($clicks[$i]);
}
echo json_encode($json_data);
回報
{"labels":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28],
"series":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57,5,17,0,2,0,0,0]}
系列必須數組系列的數組:[[0,2,4,5]]; –
對,從你的問題中我發現你已經覆蓋了,但並不是說整個數據應該在裏面和對象。 – Keno
有我的問題,我是初學者,我不知道我怎麼能返回我的數據正確的格式。我會爲我的問題添加更多信息。 –