jQuery の jqPlot で作る色を指定したトレンドライン付き折れ線グラフ

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

読み込むファイル。

JavaScript

<script>
jQuery( function() {
    jQuery . jqplot . config . enablePlugins = true;
    jQuery . jqplot(
        'jqPlot-sample',
        [
            [ [ 1, 65 ], [ 2, 72 ], [ 3, 74 ], [ 4, 63 ], [ 5, 85 ], [ 6, 70 ] ]
        ],
        {
            seriesDefaults: {
                trendline: {
                    color: '#ff0000'
                }
            }
        }
    );
} );
</script>
seriesDefaults

グラフの種類や、系列の色、太さなど、系列に関する初期設定。

trendline

トレンドラインに関するオプション。

color

トレンドラインの色。

HTML

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

スポンサード リンク

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