我尝试从 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]}