i have data database put through json_encode
following code:
$orderlist = $this->retrieve->retrieve_data('*'); $data = array(); foreach ($orderlist $order) { array_push($data, array( 'd' => $order['createddate'], 'sales' => $order['order_price'] )); } echo json_encode(array('data' => $data));
this output:
{"data":[{"d":"2015-09-26","sales":"0.00"},{"d":"2015-09-26","sales":"200.00"},{"d":"2015-09-26","sales":"45.00"},{"d":"2015-09-26","sales":"1500.00"}]}
and javascript code:
$.ajax({ url: baseurl + '/memberinfo/getgraphicalactivity', cache: false, type: "post", data: {patientfk: $("#patientfk").val()}, datatype: "json", timeout:3000, success : function (data) { memberarea = new morris.line({ element: 'line-chart-memberinfo', data: data, xkey: 'd', ykeys: ['sales'], labels: ['sales'], smooth: false, parsetime:false, resize: true }); }, error : function (xmlhttprequest, textstatus, errorthrown) { alert("error " + errorthrown); if(textstatus==='timeout') alert("request timed out"); } });
it returns error:
uncaught typeerror: cannot read property 'x' of undefined
why happening?
the issue in how building json data in php. here's code:
foreach ($orderlist $order) { $arr[] = array( 'd' => ''.$order['createddate'].'', 'sales' => ''.$order['order_price'].'', ); } echo json_encode($arr);
Comments
Post a Comment