<!-- saved from url=(0026)http://www.naturaldocs.org -->
<divid=Content><divclass="CSection"><divclass=CTopicid=MainTopic><divclass="CTitle logo"><divclass="nav"><aclass="nav"href="../../index.php"><span>></span>Home</a><aclass="nav"href="../../tests/"><span>></span>Examples</a><aclass="nav"href="../../docs/"><span>></span>Docs</a><aclass="nav"href="http://bitbucket.org/cleonello/jqplot/downloads/"><span>></span>Download</a><aclass="nav"href="../../info.php"><span>></span>Info</a><aclass="nav"href="../../donate.php"><span>></span>Donate</a></div><aname="jqPlot_Usage"></a>jqPlot Usage</div><divclass=CBody><h4class=CHeading>Usage Documentation</h4><h4class=CHeading>Introduction</h4><p>jqPlot is a jQuery plugin to generate pure client-side javascript charts in your web pages.</p><p>The jqPlot home page is at <ahref="http://www.jqplot.com/"class=LURLtarget=_top>http://www.jqplot.com/</a>.</p><p>The project page and downloads are at <ahref="http://www.bitbucket.org/cleonello/jqplot/"class=LURLtarget=_top>http://www.bitbucket.org/cleonello/jqplot/</a>.</p><p>Below are a few examples to demonstrate jqPlot usage. These plots are shown as static images. Many more examples of dynamically rendered plots can be seen on the test and examples pages here: <ahref="../../tests/"class=LURLtarget=_top>../../tests/</a>.</p><h4class=CHeading>Include the Files</h4><p>jqPlot requires jQuery (1.4+ required for certain features). jQuery is included in the distribution. To use jqPlot include jquery, the jqPlot jQuery plugin, jqPlot css file and optionally the excanvas script for IE support in your web page. Note, excanvas is required only for IE versions below 9. IE 9 includes native support for the canvas element and does not require excanvas:</p><blockquote><pre><!--[if lt IE 9]><script language="javascript" type="text/javascript" src="excanvas.js"></script><![endif]-->
<link rel="stylesheet" type="text/css" href="jquery.jqplot.css" /></pre></blockquote><h4class=CHeading>Add a plot container</h4><p>Add a container (target) to your web page where you want your plot to show up. Be sure to give your target a width and a height:</p><blockquote><pre><div id="chartdiv" style="height:400px;width:300px; "></div></pre></blockquote><h4class=CHeading>Create a plot</h4><p>Then, create the actual plot by calling the $.jqplot plugin with the id of your target and some data:</p><blockquote><pre>$.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);</pre></blockquote><p>Which will produce a chart like:</p><imgsrc="images/basicline.png"width="416"height="317"><h4class=CHeading>Plot Options</h4><p>You can customize the plot by passing options to the $.jqplot function. Options are described in <ahref="jqPlotOptions-txt.html#jqPlot_Options"class=LSectionid=link1onMouseOver="ShowTip(event, 'tt1', 'link1')"onMouseOut="HideTip('tt1')">jqPlot Options</a> in the jqPlotOptions.txt file. An example of options usage:</p><blockquote><pre>$.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]],
{ title:'Exponential Line',
axes:{yaxis:{min:-10, max:240}},
series:[{color:'#5FAB78'}]
});</pre></blockquote><p>Which will produce a plot like:</p><imgsrc="images/basicoptions.png"width="417"height="315"><h4class=CHeading>Using Plugins</h4><p>You can use jqPlot plugins (that is, plugins to the jqPlot plugin) by including them in your html after you include the jqPlot plugin. Here is how to include the log axis plugin:</p><blockquote><pre><link rel="stylesheet" type="text/css" href="jquery.jqplot.css" />
<script language="javascript" type="text/javascript" src="jqplot.logAxisRenderer.js"></script></pre></blockquote><p>Important note: For jqplot builds r529 and above (0.9.7r529 and higher), you must explicitly enable plugins via either the { show: true } plugin option to the plot or by using the $.jqplot.config.enablePlugins = true; config options set on the page before plot creation. Only plugins that can be immediately active upon loading are affected. This includes non-renderer plugins like cursor, dragable, highlighter, and trendline.</p><p>Here is the same $.jqplot call but with a log y axis:</p><blockquote><pre>$.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]],
});</pre></blockquote><p>Which produces a plot like:</p><imgsrc="images/basiclogaxis.png"width="416"height="312"><p>You can further customize with options specific to the log axis plugin:</p><blockquote><pre>$.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]],
});</pre></blockquote><p>Which makes a plot like:</p><imgsrc="images/basiclogoptions.png"width="416"height="310"><p>For a full list of options, see <ahref="jqPlotOptions-txt.html#jqPlot_Options"class=LSectionid=link2onMouseOver="ShowTip(event, 'tt1', 'link2')"onMouseOut="HideTip('tt1')">jqPlot Options</a> in the jqPlotOptions.txt file.</p><p>You can add as many plugins as you wish. Order is generally not important. Some plugins, like the highlighter plugin which highlights data points near the mouse, don’t need any extra options or setup to function. Highlighter does have additional options which the user can set.</p><p>Other plugins, the barRenderer for example, provide functionality that must be specified in the chart options object. To render a series as a bar graph with the bar renderer, you would first include the plugin after jqPlot:</p><blockquote><pre><script language="javascript" type="text/javascript" src="plugins/jqplot.barRenderer.min.js"></script></pre></blockquote><p>Then you would create a chart like:</p><blockquote><pre>$.jqplot('chartdiv', [[34.53, 56.32, 25.1, 18.6]], {series:[{renderer:$.jqplot.BarRenderer}]});</pre></blockquote><p>Here the default LineRenderer is replaced by a BarRenderer to generate a bar graph for the first (and only) series.</p></div></div></div>