mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-16 21:13:23 +01:00
120 lines
20 KiB
HTML
120 lines
20 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
|
|
|
<html><head><title>Options Tutorial</title><link rel="stylesheet" type="text/css" href="../styles/main.css"><script language=JavaScript src="../javascript/main.js"></script><script language=JavaScript src="../javascript/searchdata.js"></script></head><body class="ContentPage" onLoad="NDOnLoad()"><script language=JavaScript><!--
|
|
if (browserType) {document.write("<div class=" + browserType + ">");if (browserVer) {document.write("<div class=" + browserVer + ">"); }}// --></script>
|
|
|
|
<!-- Generated by Natural Docs, version 1.4 -->
|
|
<!-- http://www.naturaldocs.org -->
|
|
|
|
<!-- saved from url=(0026)http://www.naturaldocs.org -->
|
|
|
|
|
|
|
|
|
|
<div id=Content><div class="CSection"><div class=CTopic id=MainTopic><div class="CTitle logo"><div class="nav"><a class="nav" href="../../index.php"><span>></span>Home</a><a class="nav" href="../../tests/"><span>></span>Examples</a><a class="nav" href="../../docs/"><span>></span>Docs</a><a class="nav" href="http://bitbucket.org/cleonello/jqplot/downloads/"><span>></span>Download</a><a class="nav" href="../../info.php"><span>></span>Info</a><a class="nav" href="../../donate.php"><span>></span>Donate</a></div><a name="Options_Tutorial"></a>Options Tutorial</div><div class=CBody><p>This document will help you understand how jqPlot’s options relate to the API documentation and the jqPlot object itself. For a listing of options available to jqPlot, see <a href="jqPlotOptions-txt.html#jqPlot_Options" class=LSection id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">jqPlot Options</a> in the jqPlotOptions.txt file.</p><p>The key to effectively using jqPlot is understanding jqPlot’s options. The online documentation is API documentation. While it explains what attributes and methods various objects possess, it doesn’t explain how to use or set those attributes through options. This tutorial will help explain that.</p><p>Let’s assume you are creating a plot like this:</p><blockquote><pre>chart = $.jqplot('chart', dataSeries, optionsObj);</pre></blockquote><p>First, note that you shouldn’t try to directly set attributes on the “chart” object (like chart.grid.shadow) after your call to $.jqplot(). At best this won’t do anything **(see below). You should pass options in via the “optionsObj”.</p><p>The optionsObj really represents the plot object (jqPlot object, not to be confused with the $.jqplot function which will create a jqPlot object). Attributes you specify on that object will be merged with attributes in the jqPlot object. The axes, legend, series, etc. are attributes on the jqPlot object. The jqPlot/optionsObj object looks something like (only some attributes shown):</p><blockquote><pre>jqPlot-|
|
|
|-seriesColors
|
|
|-textColor
|
|
|-fontFamily
|
|
|-fontSize
|
|
|-stackSeries
|
|
|-series(Array)-|
|
|
| |-Series1-|
|
|
| | |-lineWidth
|
|
| | |-linePattern
|
|
| | |-shadow
|
|
| | |-showLine
|
|
| | |-showMarker
|
|
| | |-color
|
|
| |-Series2...
|
|
| |-...
|
|
| |-SeriesN
|
|
|
|
|
|-grid(Object)-|
|
|
| |-drawGridLines
|
|
| |-background
|
|
| |-borderColor
|
|
| |-borderWidth
|
|
| |-shadow
|
|
|
|
|
|-title(Object)-|
|
|
| |-text
|
|
| |-show
|
|
| |-fontFamily
|
|
| |-fontSize
|
|
| |-textAlign
|
|
| |-textColor
|
|
|
|
|
|-axes(Object)-|
|
|
| |-xais-|
|
|
| | |-min
|
|
| | |-max
|
|
| | |-numberTicks
|
|
| | |-showTicks
|
|
| | |-showTickMarks
|
|
| | |-pad
|
|
|
|
|
| ... and so on</pre></blockquote><p>The optionsObj should follow the same construction as if it were a jqPlot object (with some exceptions/shortcuts I’ll mention in a moment). So generally, when you see something like “this.drawGridLines” in the grid properties in the docs, just replace “this” with “grid” in your options object. So it becomes optionsObj.grid.drawGridLines. Do likewise with the other objects in the plot, replacing “this”, with the respective attribute on the plot like “legend” or “title”. Series and Axes are handled a little differently, because series is an array and axes has 4 distinct children “xaxis”, “yaxis”, “x2axis” and “y2axis”.</p><p>So, to remove the shadow from the grid and change the grid border size you would do:</p><blockquote><pre>optionObj = {grid:{shadow:false, borderWidth:9.0}};</pre></blockquote><p>To do the same as above but also make all the text in the plot red you would do:</p><blockquote><pre>optionObj = {
|
|
textColor:"#ff0000",
|
|
grid:{shadow:false, borderWidth:9.0}
|
|
}</pre></blockquote><p>Here is a more deeply nested example. Say you want to specify a min and max on your y axis and use a specific color for your second series. That would look like:</p><blockquote><pre>optionsObj = {
|
|
axes:{yaxis:{min:5, max:230}},
|
|
series:[{},{color:"#33ff66"}]
|
|
}</pre></blockquote><p>Note that series options are an array in order of the series data you sent in to your plot. To get to the second series, you have to put an object (even if empty) in place of the first series.</p><p>There is a handy shortcut to assign options to all axes or all series at one go. Use axesDefaults and seriesDefaults. So, if you wanted both x and y axes to start at 0 and you wanted all series to not show markers, you could do:</p><blockquote><pre>optionsObj = {axesDefaults:{min:0}, seriesDefaults:{showMarker:false}}</pre></blockquote><p>Another shortcut is for the plot title. Normally, you would assign options to the title as an object. If you specify a title option as a string, it will assign that to the title.text property automatically. So these two are equivalent:</p><blockquote><pre>optionsObj = {title:{text:"My Plot"}}</pre></blockquote><p>and</p><blockquote><pre>optionsObj = {title:"My Plot"}</pre></blockquote><p>Where things need more explanation is with renderers, plugins and their options. Briefly, what’s the difference between a renderer and a plugin.</p><p>A renderer is an object that is used to draw something and gets attached to an existing object in the plot in order to draw it. A plugin does more than just provide drawing functionality to an object; it can calculate a trend line, change the cursor, provide event driven functionality, etc. I consider renderers plugins, but plugins don’t have to be renderers.</p><p>So, how do you use renderers and plugins, and specify their options? Some common renderers are for bar charts and category axes. If you want to render your series as a bar chart with each set of bars showing up in a category on the x axis, you do:</p><blockquote><pre>optionsObj = {
|
|
seriesDefaults:{renderer:$.jqplot.BarRenderer},
|
|
axes:{xaxis:{renderer:$.jqplot.CategoryAxisRenderer}}
|
|
}</pre></blockquote><p>This replaces the default renderer used for all series in the plot with a bar renderer and the x axis default renderer (but not any other axis) with a category renderer.</p><p>Now, how would I assign options to those renderers? The renderer’s attributes may not be present in the pre-existing jqPlot object, they may be specific to the renderer. This is done through the “rendererOptions” option on the appropriate object. So, if I wanted my bars to be 25 pixels wide, I would do:</p><blockquote><pre>optionsObj = {
|
|
seriesDefaults:{
|
|
renderer:$.jqplot.BarRenderer},
|
|
rendererOptions:{
|
|
barWidth:25
|
|
},
|
|
axes:{xaxis:{renderer:$.jqplot.CategoryAxisRenderer}}
|
|
}</pre></blockquote><p>Again, this is using the “seriesDefaults” option, which will apply options to all series in the plot. You could do the same on any particular series in the plot through the “series” options array.</p><p>Plugins are free to add their own options. For example, the highlighter plugin has its own set of options that are unique to it. As a result, it responds to options placed in the “highlighter” attribute of your options object. So, if I wanted to change the highlighter tooltip to fade in and out slowly and be positioned directly above the point I’m highlighting:</p><blockquote><pre>optionsObj = {
|
|
highlighter:{tooltipFadeSpeed:'slow', tooltipLocation:'n'}
|
|
}</pre></blockquote><p>Other plugins, like dragable and trendlines, add their options in with the series. (Yes, that’s the correct name for the dragable plugin; it doesn’t use the correct spelling of “draggable”.) This is because both of those plugins can have different options for different series in the plot. So, if you wanted to specify the color for the dragable plugin and constrain it to drag only on the x axis as well as specify the color of the trend line you could do:</p><blockquote><pre>series:[{
|
|
dragable: {
|
|
color: '#ff3366',
|
|
constrainTo: 'x'
|
|
},
|
|
trendline: {
|
|
color: '#cccccc'
|
|
}
|
|
}]</pre></blockquote><p>This would apply those options to the first series only. If you had 2 series and wanted to turn off dragging and trend lines on the second series, you could do:</p><blockquote><pre>series:[{
|
|
dragable: {
|
|
color: '#ff3366',
|
|
constrainTo: 'x'
|
|
},
|
|
trendline: {
|
|
color: '#cccccc'
|
|
}
|
|
}, {
|
|
isDragable: false,
|
|
trendline:{
|
|
show: false
|
|
}
|
|
}]</pre></blockquote><p>Note, series draggability is turned off with the “isDragable” option directly on the series itself, not with a suboption of “dragable”. This may be improved in the future.</p><p>I hope this is helpful. A few key points to remember:</p><ul><li>When you see “this” in the api docs, you generally replace it with the name of the object (in lowercase) you are looking at in your options object.</li><li>seriesDefaults and axesDefaults are convenient shortcuts.</li><li>to assign options to a renderer, generally use the “rendererOptions”</li><li>plugins may add their own options attribute, like “highlighter” or “cursor”.</li></ul><p>** Note: you can set attributes after the plot is created (like plot.grid.shadow = false), but you’ll have to issue the appropriate calls to possibly reinitialize and redraw the plot. jqPlot can definitely handle this to change the plot after creation (this is how the dragable plugin updates the plot data and the trend line plugin recomputes itself when data changes). This hasn’t been documented yet, however.</p></div></div></div>
|
|
|
|
</div><!--Content-->
|
|
|
|
|
|
<div id=Footer>Copyright © 2009 - 2010 Chris Leonello · Updated March 26th, 2013 · <a href="http://www.naturaldocs.org">Generated by Natural Docs</a></div><!--Footer-->
|
|
|
|
|
|
<div id=Menu><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent1')">Usage and Options</a><div class=MGroupContent id=MGroupContent1><div class=MEntry><div class=MFile><a href="usage-txt.html">Usage</a></div></div><div class=MEntry><div class=MFile><a href="jqPlotOptions-txt.html">jqPlot Options</a></div></div><div class=MEntry><div class=MFile id=MSelected>Options Tutorial</div></div><div class=MEntry><div class=MFile><a href="jqPlotCssStyling-txt.html">jqPlot CSS Customization</a></div></div><div class=MEntry><div class=MFile><a href="changes-txt.html">Change Log</a></div></div><div class=MEntry><div class=MLink><a href="../../tests/">Examples</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent4')">API Documentation</a><div class=MGroupContent id=MGroupContent4><div class=MEntry><div class=MFile><a href="jqplot-core-js.html">jqPlot Charts</a></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent2')">Core Renderers</a><div class=MGroupContent id=MGroupContent2><div class=MEntry><div class=MFile><a href="jqplot-axisTickRenderer-js.html">Axis Tick Renderer</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-canvasGridRenderer-js.html">Canvas Grid Renderer</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-divTitleRenderer-js.html">Div Title Renderer</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-linearAxisRenderer-js.html">Linear Axis Renderer</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-markerRenderer-js.html">Marker Renderer</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-shapeRenderer-js.html">Shape Renderer</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-shadowRenderer-js.html">Shadow Renderer</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-lineRenderer-js.html">Line Renderer</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-axisLabelRenderer-js.html">Axis Label Renderer</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-themeEngine-js.html">Theme Engine</a></div></div><div class=MEntry><div class=MFile><a href="jqplot-toImage-js.html">fn</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent3')">Plugins</a><div class=MGroupContent id=MGroupContent3><div class=MEntry><div class=MFile><a href="plugins/jqplot-barRenderer-js.html">jqplot.<wbr>BarRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-BezierCurveRenderer-js.html">jqplot.<wbr>BezierCurveRenderer.js</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-blockRenderer-js.html">jqplot.<wbr>BlockRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-bubbleRenderer-js.html">jqplot.<wbr>BubbleRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-canvasAxisLabelRenderer-js.html">jqplot.<wbr>CanvasAxisLabelRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-canvasAxisTickRenderer-js.html">jqplot.<wbr>CanvasAxisTickRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-pyramidGridRenderer-js.html">jqplot.<wbr>CanvasGridRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-canvasOverlay-js.html">jqplot.<wbr>CanvasOverlay</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-categoryAxisRenderer-js.html">jqplot.<wbr>CategoryAxisRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-ciParser-js.html">jqplot.<wbr>ciParser</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-cursor-js.html">jqplot.<wbr>Cursor</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-dateAxisRenderer-js.html">jqplot.<wbr>DateAxisRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-donutRenderer-js.html">jqplot.<wbr>DonutRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-dragable-js.html">jqplot.<wbr>Dragable</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-enhancedLegendRenderer-js.html">jqplot.<wbr>enhancedLegendRenderer.js</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-funnelRenderer-js.html">jqplot.<wbr>FunnelRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-highlighter-js.html">jqplot.<wbr>Highlighter</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-logAxisRenderer-js.html">jqplot.<wbr>LogAxisRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-mekkoAxisRenderer-js.html">jqplot.<wbr>MekkoAxisRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-mekkoRenderer-js.html">jqplot.<wbr>MekkoRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-meterGaugeRenderer-js.html">jqplot.<wbr>MeterGaugeRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-ohlcRenderer-js.html">jqplot.<wbr>OHLCRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-pieRenderer-js.html">jqplot.<wbr>PieRenderer</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-pointLabels-js.html">jqplot.<wbr>PointLabels</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-pyramidAxisRenderer-js.html">jqplot.<wbr>pyramidAxisRenderer.js</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-pyramidRenderer-js.html">jqplot.<wbr>pyramidRenderer.js</a></div></div><div class=MEntry><div class=MFile><a href="plugins/jqplot-trendline-js.html">jqplot.<wbr>Trendline</a></div></div></div></div></div></div></div></div><div class=MEntry><div class=MFile><a href="gpl-2-0-txt.html">GPL License</a></div></div><div class=MEntry><div class=MFile><a href="MIT-LICENSE-txt.html">MIT License</a></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent5')">Index</a><div class=MGroupContent id=MGroupContent5><div class=MEntry><div class=MIndex><a href="../index/General.html">Everything</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Classes.html">Classes</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Properties.html">Properties</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Functions.html">Functions</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Hooks.html">Hooks</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Files.html">Files</a></div></div></div></div></div><script type="text/javascript"><!--
|
|
var searchPanel = new SearchPanel("searchPanel", "HTML", "../search");
|
|
--></script><div id=MSearchPanel class=MSearchPanelInactive><input type=text id=MSearchField value=Search onFocus="searchPanel.OnSearchFieldFocus(true)" onBlur="searchPanel.OnSearchFieldFocus(false)" onKeyUp="searchPanel.OnSearchFieldChange()"><select id=MSearchType onFocus="searchPanel.OnSearchTypeFocus(true)" onBlur="searchPanel.OnSearchTypeFocus(false)" onChange="searchPanel.OnSearchTypeChange()"><option id=MSearchEverything selected value="General">Everything</option><option value="Classes">Classes</option><option value="Files">Files</option><option value="Functions">Functions</option><option value="Hooks">Hooks</option><option value="Properties">Properties</option></select></div><script language=JavaScript><!--
|
|
HideAllBut([1, 4, 5], 6);// --></script></div><!--Menu-->
|
|
|
|
|
|
|
|
<!--START_ND_TOOLTIPS-->
|
|
<div class=CToolTip id="tt1"><div class=CSection><b>This document is out of date. </div></div><!--END_ND_TOOLTIPS-->
|
|
|
|
|
|
|
|
|
|
<div id=MSearchResultsWindow><iframe src="" frameborder=0 name=MSearchResults id=MSearchResults></iframe><a href="javascript:searchPanel.CloseResultsWindow()" id=MSearchResultsWindowClose>Close</a></div>
|
|
|
|
|
|
<script language=JavaScript><!--
|
|
if (browserType) {if (browserVer) {document.write("</div>"); }document.write("</div>");}// --></script></body></html> |