jquery根据返回的json数据绘制图表


jquery charts from returned json data

我已经使用mysql和php从数据库中获取了json数据,现在我想使用$.ajax函数将其传递回来,并从中动态创建一个样条曲线图。任何帮助或示例都将不胜感激。同样对于多次验血的日期重复,我怎么能只显示一个日期的多次验血结果。

这是我的php代码

header('Set Access-Control-Allow-Origin: *');
header('Content-type: application/json');
require_once"conn.php";
if($_SERVER['REQUEST_METHOD']=='GET'){
//recieve credentials from the user 
$nhsno = mysqli_real_escape_string($conn, $_GET['pnhsno']);
//check the variables recieved are not empty
    if($nhsno != ''){
        $sql = "SELECT date,name,tname,value FROM examination e, testresults t, examtype ex, testname tn
        WHERE e.patientnhs_no = '$nhsno' and e.etype_id = '1' and
        e.examination_id = t.examination_id and e.etype_id = ex.etype_id and t.tname_id = tn.tname_id ";//create an sql statement 
        $result = $conn->query($sql);//run sqlm statement 
        $row = $result->fetch_assoc(); //fetch row of data

    foreach ($result as $row){
        $return[]=array('date'=>$row['date'],
                        'name'=>$row['name'],
                        'test name'=>$row['tname'],
                        'value'=>$row['value']);
    }
}
}
$conn = null;
echo json_encode($return);

?>

这是我的json输出

[{"date":"2004-07-05","name":"blood test","test name":"t3","value":"6.8"},  {"date":"2004-07-05","name":"blood test","test name":"t4","value":"29"},{"date":"2004-07-05","name":"blood test","test name":"tsh","value":"0.01"},{"date":"2004-07-05","name":"blood test","test name":"thyroglobulin level","value":"0.5"},{"date":"2005-06-15","name":"blood test","test name":"t3","value":"5.2"},{"date":"2005-06-15","name":"blood test","test name":"t4","value":"30"},{"date":"2005-06-15","name":"blood test","test name":"tsh","value":"0.02"},{"date":"2005-06-15","name":"blood test","test name":"thyroglobulin level","value":"0.5"}]  

因为混合了很多东西,并且在循环之前提取了1行。

应该是这样的:

$result = $conn->query($sql); //run sqlm statement 
//Do not need this!
//$row = $result->fetch_assoc(); //fetch row of data
//And $row = $result... not opposite.
while ($row = $result->fetch_assoc()) {
    $return[] = array('date' => $row['date'],
        'name' => $row['name'],
        'test name' => $row['tname'],
        'value' => $row['value']);
}