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>
<script language="javascript" type="text/javascript" src="plugins/jqplot.barRenderer.min.js"></script>
<script language="javascript" type="text/javascript" src="plugins/jqplot.categoryAxisRenderer.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.barRenderer.min.js"></script>
<script language="javascript" type="text/javascript" src="plugins/jqplot.categoryAxisRenderer.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" />
読み込むファイル。
- jquery-1.7.1.min.js
- jquery.jqplot.min.js
- jqplot.barRenderer.min.js
- jqplot.categoryAxisRenderer.min.js
- jqplot.pointLabels.min.js
- 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,
showMarker: false,
seriesDefaults: {
renderer: jQuery . jqplot . BarRenderer,
pointLabels: {
show: true,
location: 's',
stackedValue: true,
formatString: '%d'
}
},
axes: {
xaxis: {
label: '月',
renderer: jQuery . jqplot . CategoryAxisRenderer,
},
yaxis: {
label: '点数',
ticks: [ 0, 100, 200, 300, 400 ],
tickOptions: {
formatString: '%d'
}
}
},
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,
showMarker: false,
seriesDefaults: {
renderer: jQuery . jqplot . BarRenderer,
pointLabels: {
show: true,
location: 's',
stackedValue: true,
formatString: '%d'
}
},
axes: {
xaxis: {
label: '月',
renderer: jQuery . jqplot . CategoryAxisRenderer,
},
yaxis: {
label: '点数',
ticks: [ 0, 100, 200, 300, 400 ],
tickOptions: {
formatString: '%d'
}
}
},
series: [
{
label: '国語'
},
{
label: '算数'
},
{
label: '理科'
},
{
label: '社会'
}
],
legend: {
show: true,
placement: 'outside',
location: 'ne',
}
}
);
} );
</script>
HTML
<div id="jqPlot-sample" style="height: 400px; width: 400px;"></div>