jQuery の jqPlot の線グラフに加える水平の実線の始点と終点を指定

jQueryのjqPlotプラグインで作る複数系列の折れ線グラフにおいて、指定したYの値に、水平の実線を描き加え、その水平の実線の始点と終点を、Xの値の最小値と最大値で指定する方法。

実装例(サンプル)

実装例(サンプル)のソースコード

読み込み

パスは、それぞれ、アップロードした場所を指定する。

<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.canvasOverlay.min.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.jqplot.min.css" />

読み込むファイル。

JavaScript

<script>
jQuery( function() {
    jQuery . jqplot(
        'jqPlot-sample',
        [
            [ [ 1, 83 ], [ 2, 61 ], [ 3, 79 ], [ 4, 88 ], [ 5, 62 ], [ 6, 75 ] ],
            [ [ 1, 75 ], [ 2, 86 ], [ 3, 71 ], [ 4, 26 ], [ 5, 58 ], [ 6, 62 ] ],
            [ [ 1, 25 ], [ 2, 52 ], [ 3, 74 ], [ 4, 63 ], [ 5, 85 ], [ 6, 96 ] ]
        ],
        {
            axes: {
                yaxis: {
                    ticks: [ '0', '25', '50', '75', '100' ],
                }
            },
            canvasOverlay: {
                show: true,
                objects: [
                    {
                        horizontalLine: {
                            y: 88,
                            lineWidth: 2,
                            color: '#4bb2c5',
                            lineCap: 'round',
                            xmin: 3.5,
                            xmax: 4.5,
                        }
                    },
                    {
                        horizontalLine: {
                            y: 61,
                            lineWidth: 2,
                            color: '#4bb2c5',
                            lineCap: 'round',
                            xmin: 1.5,
                            xmax: 2.5,
                        }
                    },
                    {
                        horizontalLine: {
                            y: 96,
                            lineWidth: 2,
                            color: '#c5b47f',
                            lineCap: 'round',
                            xmin: 5.5,
                            xmax: 6.5,
                        }
                    },
                    {
                        horizontalLine: {
                            y: 25,
                            lineWidth: 2,
                            color: '#c5b47f',
                            lineCap: 'round',
                            xmin: 0.5,
                            xmax: 1.5,
                        }
                    },
                    {
                        horizontalLine: {
                            y: 86,
                            lineWidth: 2,
                            color: '#eaa228',
                            lineCap: 'round',
                            xmin: 1.5,
                            xmax: 2.5,
                        }
                    },
                    {
                        horizontalLine: {
                            y: 26,
                            lineWidth: 2,
                            color: '#eaa228',
                            lineCap: 'round',
                            xmin: 3.5,
                            xmax: 4.5,
                        }
                    }
                ]
            }
        }
    );
} );
</script>
axes

軸に関するオプション。

yaxis

Y軸に関するオプション。

ticks

Y軸上の目盛りを指定。

指定しない場合は、自動的に計算する。

canvasOverlay

グラフに描き加える線に関するオプション。

show

グラフに線を描き加えるか。「true」は表示。「false」は非表示。初期設定値は「false」。

objects

描き加える線の種類ごとに、配列で指定。

horizontalLine

水平の実線。

y

水平の実線を描き加えるYの値。

lineWidth

水平の実線の太さ。

color

水平の実線の色。

shadow

水平の実線の影を表示するか。「true」は表示。「false」は非表示。

lineCap

水平の実線の端の形。

  • round:円形
  • butt:四角形
  • square:四角形

xmin

描き加える水平線の最小のXの値。

xmax

描き加える水平線の最大のXの値。

HTML

<div id="jqPlot-sample" style="height: 300px; width: 400px;"></div>

スポンサード リンク

カテゴリー: canvasOverlay, JavaScript, jqPlot, jQuery, グラフ、チャート, プラグイン, 線グラフ パーマリンク