Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Content/jqplot/src/optionsTutorial.txt @ 13401

Last change on this file since 13401 was 9062, checked in by fschoepp, 12 years ago

#1888:
Backend changes:

  • Simplified job state detection (only one hive call will be made to detect all states now, instead of one additional call per job)
  • Reorganized classes (moved model classes into Model folder)

Website changes:

  • Website now heavily uses JavaScript to achieve better user experience
  • JavaScript degrades gracefully, except for plots
  • Tables: Added jquery-datatable-plugin to extend tables (pagination + search functionality)
  • OaaS-Website now uses the design of the HL websites (found in WebApplication branch)
  • Added jqplot to render zoomable line plots for HL-Datatables
  • Styling.js: Plots will be generated by using an ajax call; additional jquery-styling occurs within this file.
  • Added jquery-ui-1.9.2 which is capable of handling/rendering tabs, accordions and resizers.
File size: 8.6 KB
Line 
1Title: Options Tutorial
2
3This document will help you understand how jqPlot's options
4relate to the API documentation and the jqPlot object
5itself.  For a listing of options available to jqPlot,
6see <jqPlot Options> in the jqPlotOptions.txt file.
7
8The key to effectively using jqPlot is understanding jqPlot's
9options.  The online documentation is API documentation.  While
10it explains what attributes and methods various objects posses,
11it doesn't explain how to use or set those attributes through
12options.  This tutorial will help explain that.
13
14Lets assume you are creating a plot
15like this:
16
17> chart = $.jqplot('chart', dataSeries, optionsObj);
18
19First, note that you shouldn't try to directly set attributes on the
20"chart" object (like chart.grid.shadow) after your call to $.jqplot(). 
21At best this won't do anything **(see below). You should pass options in via
22the "optionsObj".
23
24the optionsObj really represents the plot object (jqPlot object, not
25to be confused with the $.jqplot function which will create a jqPlot
26object).  Attributes you specify on that object will be merged with
27attributes in the jqPlot object.  The axes, legend, series, etc. are
28attributes on the jqPlot object.  The jqPlot/optionsObj object looks
29something like (only some attributes shown):
30
31> jqPlot-|
32>        |-seriesColors
33>        |-textColor
34>        |-fontFamily
35>        |-fontSize
36>        |-stackSeries
37>        |-series(Array)-|
38>        |               |-Series1-|
39>        |               |         |-lineWidth
40>        |               |         |-shadow
41>        |               |         |-showLine
42>        |               |         |-showMarker
43>        |               |         |-color
44>        |               |-Series2...
45>        |               |-...
46>        |               |-SeriesN
47>        |
48>        |-grid(Object)-|
49>        |              |-drawGridLines
50>        |              |-background
51>        |              |-borderColor
52>        |              |-borderWidth
53>        |              |-shadow
54>        |
55>        |-title(Object)-|
56>        |               |-text
57>        |               |-show
58>        |               |-fontFamily
59>        |               |-fontSize
60>        |               |-textAlign
61>        |               |-textColor
62>        |
63>        |-axes(Object)-|
64>        |              |-xais-|
65>        |              |      |-min
66>        |              |      |-max
67>        |              |      |-numberTicks
68>        |              |      |-showTicks
69>        |              |      |-showTickMarks
70>        |              |      |-pad
71>        |
72>        | ... and so on
73 
74The optionsObj should follow the same construction as if it were a
75jqPlot object (with some exceptions/shortcuts I'll mention in a
76moment).  So generally, when you see something like
77"this.drawGridLines" in the grid properties in the docs, just replace
78"this" with "grid" in your options object.  So it becomes
79optionsObj.grid.drawGridLines.  Do likewise with the other objects in
80the plot, replacing "this", with the respective attribute on the plot
81like "legend" or "title".  Series and Axes are handled a little
82different, because series is an array and axes has 4 distinct children
83"xaxis", "yaxis", "x2axis" and "y2axis".
84
85So, to remove the shadow from the grid and change the grid border size
86you would do:
87
88> optionObj = {grid:{shadow:false, borderWidth:9.0}};
89
90To do the same as above but also make all the text in the plot red you
91would do:
92
93> optionObj = {
94>    textColor:"#ff0000",
95>    grid:{shadow:false, borderWidth:9.0}
96> }
97
98Here is a more deeply nested example. Say you want to specify a min
99and max on your y axis and use a specific color for your second
100series.  That would look like:
101
102> optionsObj = {
103>    axes:{yaxis:{min:5, max:230}},
104>    series:[{},{color:"#33ff66"}]
105> }
106
107Note that series options are an array in order of the series data you
108sent in to your plot.  To get to the second series, you have to put an
109object (even if empty) in place of the first series.
110
111There is a handy shortcut to assign options to all axes or all series
112at one go.  Use axesDefaults and seriesDefaults.  So, if you wanted
113both x and y axes to start at 0 and you wanted all series to not show
114markers, you could do:
115
116> optionsObj = {axesDefaults:{min:0}, seriesDefaults:{showMarker:false}}
117
118Another shortcut is for the plot title.  Normally, you would assign
119options to the title as an object.  If you specify a title option as a
120string, it will assign that to the title.text property automatically.
121So these two are equivalent:
122
123> optionsObj = {title:{text:"My Plot"}}
124
125and
126
127> optionsObj = {title:"My Plot"}
128
129Where things need more explaination is with renderers, plugins and
130their options.  Briefly, what's  renderer, what's a plugin.
131
132A renderer is an object that is used to draw something and gets
133attached to an existing object in the plot in order to draw it.  A
134plugin does more than just provide drawing functionality to an
135object.  It will do more like calculate a trend line, change the
136cursor, provide event driven functionality, etc.  I consider renderers
137plugins, but plugins don't have to be renderers.
138
139So, how do you use renderers, plugins, and specify their options?
140Some common renderes are for bar charts and category axes.  If you
141want to render your series as a bar chart with each set of bars
142showing up in a category on the x axis, you do:
143
144> optionsObj = {
145>    seriesDefaults:{renderer:$.jqplot.BarRenderer},
146>    axes:{xaxis:{renderer:$.jqplot.CategoryAxisRenderer}}
147> }
148
149This replaces the default renderer used for all series in the plot
150with a bar renderer and the x axis default renderer (but not any other
151axis) with a category renderer.
152
153Now, how would I assign options to those renderers?  The renderer's
154attributes may not be present in the pre-existing jqPlot object, they
155may be specific to the renderer.  This is done through the
156"rendererOptions" option on the appropriate object. So, if I wanted my
157bars to be 25 pixels wide, I would do:
158
159
160> optionsObj = {
161>    seriesDefaults:{
162>        renderer:$.jqplot.BarRenderer},
163>        rendererOptions:{
164>            barWidth:25
165>        },
166>    axes:{xaxis:{renderer:$.jqplot.CategoryAxisRenderer}}
167> }
168
169Again, this is using the "seriesDefaults" option, which will apply
170options to all series in the plot.  You could do the same on any
171particular series in the plot through the "series" options array.
172
173Plugins are free to add their own options.  For example, the
174highlighter plugin has it's own set of options that are unique to it.
175As a result, it responds to options placed in the "highlighter"
176attribute of your options object.  So, if I wanted to change the
177highlighter tooltip to fade in and out slowly and be positioned
178directly above the point I'm highlighting:
179
180> optionsObj = {
181>     highlighter:{tooltipFadeSpeed:'slow', tooltipLocation:'n'}
182> }
183
184Other plugins, like dragable and trendlines, add their options in with
185the series.  This is because both of those plugins can have different
186options for different series in the plot.  So, if you wanted to specify the
187color of the dragable and constrain it to drag only on the x axis as well
188as specify the color of the trend line you could do:
189
190> series:[{
191>     dragable: {
192>         color: '#ff3366',
193>         constrainTo: 'x'
194>     },
195>     trendline: {
196>         color: '#cccccc'
197>     }
198> }]
199
200This would apply those options to the first series only.  If you had 2 series
201and wanted to turn off dragging and trend lines on the second series, you could do:
202
203> series:[{
204>     dragable: {
205>         color: '#ff3366',
206>         constrainTo: 'x'
207>     },
208>     trendline: {
209>         color: '#cccccc'
210>     }
211> }, {
212>    isDragable: false,
213>    trendline:{
214>        show: false
215>    }
216> }]
217
218Note, series dragability is turned off with the "isDragable" option directly on
219the series itself, not with a suboption of "dragable".  This may be improved
220in the future.
221
222I hope this is helpful.
223A few key points to remember:
224
225- When you see "this" in the api docs, you generally replace it with
226the name of the object (in lowercase) you are looking at in your
227options object.
228- seriesDefaults and axesDefaults are convenient shortcuts.
229- to assign options to a renderer, generally use the "rendererOptions"
230- plugins may add their own options attribute, like "highlighter" or
231"cursor".
232
233** Note:  you can set attributes after the plot is created (like
234plot.grid.shadow = false), but you'll have to issue the appropriate
235calls to possibly reinitialize and redraw the plot.  jqPlot can
236definitely handle this to change the plot after creation (this is how
237the dragable plugin updates the plot data and the trend line plugin
238recomputes itself when data changes).  This hasn't been documented
239yet, however.
Note: See TracBrowser for help on using the repository browser.