[jqPlotライブラリ] 折れ線グラフを表示する

説明

jqPlotライブラリで折れ線グラフを表示するにはグラフを表示する領域をdivタグで用意しID名を割り当てておきます。次にグラフのデータを配列に用意します。ページが構築されたら$.jqplot()の最初のパラメータにグラフを表示するdivタグのID名を、2番目のパラメータにグラフに表示する配列データを指定します。この2番目のパラメータは二次元配列として指定します。

サンプルプログラム

【HTML】
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="css/jquery.jqplot.css" type="text/css" media="all">
<link rel="stylesheet" href="css/main.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/excanvas.js"></script>
<script type="text/javascript" src="js/jquery.jqplot.js"></script>
<script type="text/javascript" src="js/plugins/jqplot.barRenderer.min.js"></script>
<script type="text/javascript" src="js/sample.js"></script>
</head>
<body>
<h1>jqPlotサンプル</h1>
<div id="myGraph" style="width:640;height:480px;"></div>
</body>
</html>


【sample.js】
$(function(){
var data = [4,6,4,9,5,9,6,3];
$.jqplot("myGraph", [data],{
series : [
{ renderer : $.jqplot.BarRenderer }
]
});
});
サンプルを実行
[戻る]