jQueryのjqPlotプラグインで、科目別得点推移の積み上げ面グラフ(層グラフ、エリアグラフ)を描くチュートリアル。
実装例(サンプル)
実装例(サンプル)のソースコード
読み込み
パスは、それぞれ、アップロードした場所を指定する。
<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>
<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>
<link rel="stylesheet" type="text/css" href="jquery.jqplot.min.css" />
読み込むファイル。
JavaScript
<script>
jQuery( function() {
Kokugo = [ [ 1, 23 ], [ 2, 34 ], [ 3, 52 ], [ 4, 47 ], [ 5, 78 ], [ 6, 66 ] ];
Sansuu = [ [ 1, 65 ], [ 2, 72 ], [ 3, 74 ], [ 4, 63 ], [ 5, 85 ], [ 6, 90 ] ];
Rika = [ [ 1, 83 ], [ 2, 81 ], [ 3, 79 ], [ 4, 88 ], [ 5, 78 ], [ 6, 96 ] ];
Shakai = [ [ 1, 81 ], [ 2, 86 ], [ 3, 71 ], [ 4, 69 ], [ 5, 58 ], [ 6, 82 ] ];
jQuery . jqplot(
'jqPlot-sample',
[
Kokugo, Sansuu, Rika, Shakai
],
{
title: '科目別得点推移の積み上げ折れ線グラフ',
stackSeries: true,
axes: {
xaxis: {
pad: 0,
label: '月',
ticks: [ '1', '2', '3', '4', '5', '6' ]
},
yaxis: {
label: '点数',
min: 0,
max: 400,
}
},
seriesDefaults: {
showMarker: false,
fill: true
},
series: [
{
label: '国語'
},
{
label: '算数'
},
{
label: '理科'
},
{
label: '社会'
}
],
legend: {
show: true,
placement: 'outside',
location: 'ne',
}
}
);
} );
</script>
jQuery( function() {
Kokugo = [ [ 1, 23 ], [ 2, 34 ], [ 3, 52 ], [ 4, 47 ], [ 5, 78 ], [ 6, 66 ] ];
Sansuu = [ [ 1, 65 ], [ 2, 72 ], [ 3, 74 ], [ 4, 63 ], [ 5, 85 ], [ 6, 90 ] ];
Rika = [ [ 1, 83 ], [ 2, 81 ], [ 3, 79 ], [ 4, 88 ], [ 5, 78 ], [ 6, 96 ] ];
Shakai = [ [ 1, 81 ], [ 2, 86 ], [ 3, 71 ], [ 4, 69 ], [ 5, 58 ], [ 6, 82 ] ];
jQuery . jqplot(
'jqPlot-sample',
[
Kokugo, Sansuu, Rika, Shakai
],
{
title: '科目別得点推移の積み上げ折れ線グラフ',
stackSeries: true,
axes: {
xaxis: {
pad: 0,
label: '月',
ticks: [ '1', '2', '3', '4', '5', '6' ]
},
yaxis: {
label: '点数',
min: 0,
max: 400,
}
},
seriesDefaults: {
showMarker: false,
fill: true
},
series: [
{
label: '国語'
},
{
label: '算数'
},
{
label: '理科'
},
{
label: '社会'
}
],
legend: {
show: true,
placement: 'outside',
location: 'ne',
}
}
);
} );
</script>
HTML
<div id="jqPlot-sample" style="height: 300px; width: 400px;"></div>