MYSQLのデータを動的にチャート表示させたいです。
json.htmlのDATAにjson.phpから受け取った値を入れたいのですが、どなたかご教授頂けないでしょうか?
chart_tbl
id,date(日付),start(始値),high(高値),low(低値),end(終値)
-------- json.php ----------
$dsn = 'mysql:dbname=rensai-comic-net00005;host=localhost;charset=utf8';
//ユーザ名
$user = 'user';
//パスワード
$password = 'password';
try
{
//nullで初期化
$users = null;
//DBに接続 $dbh = new PDO($dsn, $user, $password); //'users' テーブルのデータを取得する $sql = 'select * from chart'; $stmt = $dbh->query($sql); //取得したデータを配列に格納 while ($row = $stmt->fetchObject()) { $users[] = array( 'id'=> $row->id ,'date' => $row->date ,'start' => $row->start ,'high' => $row->high ,'low' => $row->low ,'end' => $row->end ); } //JSON形式で出力する header('Content-Type: application/json'); echo json_encode( $users ); exit;
}
catch (PDOException $e)
{
//例外処理
die('Error:' . $e->getMessage());
}
?>
-------- json.html ----------
//返ってきたデータの表示
//---------------------------------
jQuery . jqplot(
'jqPlot-sample',
[
//-----------------------------------------------------DATA(現在は生のデータ)
[
[ '2012-01-01 0:00AM', 62, 70, 57, 68 ],
[ '2012-02-01 0:00AM', 70, 83, 68, 76 ],
[ '2012-03-01 0:00AM', 75, 96, 72, 94 ],
[ '2012-04-01 0:00AM', 93, 95, 72, 84 ],
[ '2012-05-01 0:00AM', 85, 86, 67, 71 ],
[ '2012-06-01 0:00AM', 75, 88, 75, 82 ]
]
//-----------------------------------------------------DATA
],
{
seriesDefaults: {
renderer: jQuery . jqplot . OHLCRenderer,
rendererOptions: {
candleStick: true
}
},
axes:{
xaxis:{
renderer: jQuery . jqplot . DateAxisRenderer,
min: '2011-12-01 0:00AM',
max: '2012-08-01 0:00AM',
tickInterval: '1 months',
tickOptions:{
formatString: '%B'
},
}
},
}
);
//----------------------------------
},
/**
* Ajax通信が失敗場合に呼び出されるメソッド
*/
error: function(XMLHttpRequest, textStatus, errorThrown)
{
//エラーメッセージの表示
alert('Error : ' + errorThrown);
}
});
});
</script>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/30 11:39
2016/07/01 00:21
2016/07/01 10:33
2016/07/01 12:11
2016/07/02 02:48