This page demonstrates placing plots within jQuery UI widgets. Tab 2 and tab 3 contain plots. Using a combination of alternate sizing specification and the jqplot "replot" method the plots are properly displayed when their containers are shown.

The alternate sizing specifications for setting plot height and width are needed because a hidden element (or child of a hidden element) has no size. The first example in tab 2 uses custom "data-height" and "data-width" attributes on the plot target element. The second example uses "width" and "height" properties specified on the options object passed into the $.jqplot() function.

The default plot size is 300px wide by 400px high. The default setting can be overridden by specifying different values to the $.jqplot.config.defaultHeight and $.jqplot.config.defaultWidth properties. Height and width values are taken in this order of precedence:

1. The css properties of the plot target if available (not available with display:none;).
2. Options object passed into the $.jqplot() function.
3. Custom data-height and data-width attributes on the plot target.
4. The config defaults.

- Tab 1
- Tab 2
- Tab 3

Tabs 2 and 3 have plots. Since tabs 2 and 3 are initially inactive, their contents (and the plots) are initially hidden.

This plot was in an initially hidden container. Its height and width are set by the "data-height" and "data-width" properties of the plot container.

This plot is in an initially hidden container. Its height and width are set by the 'height' and 'width' properties of the options object passed into the plot constructor.

In the accordion below, section 2 contains a plot. Sizing plots in hidden accordion sections is very similar to sizing in a tab widget. Because of the default animation on accordions, however, the plot will not draw itself until the entire accordion panel is shown.

### Section 1

Here is section 1 there is no plot. Section 2 has a plot that will display once the section is completely shown.

### Section 2

This plot also has its height and width set with the data-height and data-width attributes. Note, if you want the accordion widget to properly size itself before the plot is shown, you must also specify a css height and width on the plot target.

Code for generating the plots follows. It is critical to bind the callback to the UI widgets "show" or "change" method which calls the plots "replot" method. Without this, the plot won't properly redraw itself when its container becomes visible.

Note in the ui.index and plot._drawCount properties in the tabsshow callback. ui.index gives the index of the activated tab. plot._drawCount keeps track of how many times the plot was visibly drawn (or redrawn/replotted). Generally, replot only needs to be called the first time the plot is visibly drawn, hence the check for plot._drawCount === 0.

AJAX and JSON Data Loading via Data Renderers
Animated Charts
Animated Dashboard Sample - Filled Line with Log Axis
Area Chart
Area Chart 2
Axis Labels
Axis Labels and Rotated Text
Bar Charts
Bar Colors Example
Bezier Curve Plots
Block Plots
Bubble Charts
Bubble Plots
Candlestick and Open Hi Low Close Charts
Chart Theming
Charts with Fill Between Lines
Cumulative Density Function Chart
Dashed Lines with Smoothing
Data Point Highlighting, Tooltips and Cursor Tracking
Data Point labels
Date Axes
Date Axes 2
Date Axes, Rotated Labels and Zooming
Draw Lines on Plots - Canvas Overlay
Draw Rectangles on Plots
Engel Curves
Error Bands and Confidence Intervals
Filled (Area) Charts
Force Plot to Have Tick at 0 or 100
Hidden Plots
Highlighting, Dragging Points, Cursor and Trend Lines
Line Charts and Options
Lorenz Curves
Mekko Charts
Meter Gauge
Open Hi Low Close and Candlestick Charts
Pie Charts and Options
Pie Charts and Options 2
Pie Charts with Enhanced Legend Renderer
Pie and Donut Charts
Plot Creation with jQuery Selectors
Plot Zooming and Cursor Control
Probability Density Function Chart
Pyramid Chart By Age
Pyramid Charts
Pyramid Charts 2
Quintile Pyramid Charts
Resizable Plots
Rotated Labels and Font Styling
Smoothed Lines
Step Charts
Vertical and Horizontal Bar Charts
Waterfall Charts
Waterfall Charts 2
Zoom Options
Zoom Proxy - Control one plot from another
Zooming
Zooming with Date and Log Axes