jQueryのjqPlotプラグインで、散布図(分布図・点グラフ)を作る方法。
- seriesDefaultsオプション内のcolorプロパティに「#7dffc7」を指定。
- seriesDefaultsオプション内のshowLineプロパティに「false」を指定し、系列の線を非表示にする。
- seriesDefaultsオプション内のmarkerOptionsのsizeプロパティに「16」を指定し、マーカーのサイズを大きくする。
- 「plugins」フォルダ内の、「jqplot.pointLabels.min.js」を読み込む。
- seriesDefaultsオプション内のpointLabelsのshowプロパティに「true」を指定し、データポイントラベルを表示。
- seriesDefaultsオプション内のpointLabelsのlocationプロパティに「n」を指定し、データポイントラベルの位置を上にする。
- seriesDefaultsオプション内のpointLabelsのypaddingプロパティに「-12」を指定し、データポイントラベルの垂直方向の位置を調整。
実装例(サンプル)
実装例(サンプル)のソースコード
読み込み
パスは、それぞれ、アップロードした場所を指定する。
<script language="javascript" type="text/javascript" src="jquery-1.7.1.min.js"></script>
<!--[if lt IE 9]>
<script language="javascript" type="text/javascript" src="excanvas.min.js"></script>
<![endif]-->
<script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
<script language="javascript" type="text/javascript" src="plugins/jqplot.pointLabels.min.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.jqplot.min.css" />
<!--[if lt IE 9]>
<script language="javascript" type="text/javascript" src="excanvas.min.js"></script>
<![endif]-->
<script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
<script language="javascript" type="text/javascript" src="plugins/jqplot.pointLabels.min.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.jqplot.min.css" />
読み込むファイル。
JavaScript
<script>
jQuery( function() {
jQuery . jqplot(
'jqPlot-sample',
[
[ [ 88, 65, 'A' ], [ 36, 22, 'B' ], [ 33, 54, 'C' ], [ 51, 63, 'D' ], [ 21, 91, 'E' ], [ 45, 79, 'F' ] ]
],
{
seriesDefaults: {
color: '#7dffc7',
showLine: false,
markerOptions: {
size: 16
},
pointLabels: {
show: true,
location: 'n',
ypadding: -12,
}
}
}
);
} );
</script>
jQuery( function() {
jQuery . jqplot(
'jqPlot-sample',
[
[ [ 88, 65, 'A' ], [ 36, 22, 'B' ], [ 33, 54, 'C' ], [ 51, 63, 'D' ], [ 21, 91, 'E' ], [ 45, 79, 'F' ] ]
],
{
seriesDefaults: {
color: '#7dffc7',
showLine: false,
markerOptions: {
size: 16
},
pointLabels: {
show: true,
location: 'n',
ypadding: -12,
}
}
}
);
} );
</script>
- seriesDefaults
- グラフの種類や、系列の色、太さなど、系列に関する初期設定オプション。 - color
- showLine
- 系列の線を表示するか。「true」は表示。「false」は非表示。初期設定値は、「true」。 
- markerOptions
- 系列のマーカーに関するオプション。 - size
- 系列のマーカーの大きさ。初期設定値は、「9」。 
 
- pointLabels
- データポイントに関するオプション。 - show
- データポイントを表示するかどうか。「true」は表示。「false」は非表示。初期設定値は、「false」。 
- location
- データポイントを配置する位置(方角)。 - nw: 左上
- n: 上
- ne: 右上
- e: 右
- se: 右下
- s: 下
- sw: 左下
- w: 左
 
 
- ypadding
- データポイントとラベルの間の垂直方向のパディング。 
 
 
HTML
<div id="jqPlot-sample" style="height: 300px; width: 300px;"></div>