hiddenPlotsInTabs.html
9.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html>
<head>
<title>Hidden Plots</title>
<link class="include" rel="stylesheet" type="text/css" href="../jquery.jqplot.min.css" />
<link rel="stylesheet" type="text/css" href="examples.min.css" />
<link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shCoreDefault.min.css" />
<link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shThemejqPlot.min.css" />
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../excanvas.js"></script><![endif]-->
<script class="include" type="text/javascript" src="../jquery.min.js"></script>
</head>
<body>
<div class="logo">
<div class="nav">
<a class="nav" href="../../../index.php"><span>></span>Home</a>
<a class="nav" href="../../../docs/"><span>></span>Docs</a>
<a class="nav" href="../../download/"><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>
</div>
<div class="example-content">
<div class="example-nav">
<a href="fillBetweenLines.html">Previous</a> <a href="./">Examples</a> <a href="kcp_area.html">Next</a></div>
<!-- Example scripts go here -->
<style type="text/css">
.ui-tabs, .ui-accordion {
width: 690px;
margin: 2em auto;
}
.ui-tabs-nav, .ui-accordion-header {
font-size: 12px;
}
.ui-tabs-panel, .ui-accordion-content {
font-size: 14px;
}
.jqplot-target {
font-size: 18px;
}
ol.description {
list-style-position: inside;
font-size:15px;
margin:1.5em auto;
padding:0 15px;
width:600px;
}
</style>
<p class="description">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.</p>
<p class="description">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.</p>
<p class="description">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:
</p>
<ol class="description">
<li>The css properties of the plot target if available (not available with display:none;).</li>
<li>Options object passed into the $.jqplot() function.</li>
<li>Custom data-height and data-width attributes on the plot target.</li>
<li>The config defaults.</li>
</ol>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Tab 1</a></li>
<li><a href="#tabs-2">Tab 2</a></li>
<li><a href="#tabs-3">Tab 3</a></li>
</ul>
<div id="tabs-1">
Tabs 2 and 3 have plots. Since tabs 2 and 3 are initially inactive, their contents (and the plots) are initially hidden.
</div>
<div id="tabs-2">
<p>This plot was in an initially hidden container. It's hieght and width are set by the "data-height" and "data-width" properties of the plot container.</p>
<div id="chart1" data-height="260px" data-width="480px" style="margin-top:20px; margin-left:20px;"></div>
</div>
<div id="tabs-3">
<p>This plot is in an initially hidden container. It's height and width are set by the 'height' and 'width' properties of the options object passed into the plot constructor.</p>
<div id="chart2" style="margin-top:20px; margin-left:20px;"></div>
</div>
</div>
<p class="description">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.</p>
<div id="accordion" style="margin-top:50px">
<h3><a href="#">Section 1</a></h3>
<div>
Here is section 1 there is no plot. Section 2 has a plot that will display once the section is completely shown.
</div>
<h3><a href="#">Section 2</a></h3>
<div>
<p>
This plot also has it's height and width set with the data-height and data-width attributes. Note, if you want the accordion widget to properly size itself </em>before</em> the plot is shown, you must also specify a css height and width on the plot target.
</p>
<div id="chart3" data-height="200" data-width="400" style="width:400px; height: 200px; margin-top: 20px; margin-left: 20px"></div>
</div>
</div>
<p class="description">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 it's container becomes visible.</p>
<p class="description">
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.
</p>
<pre class="code brush:js"></pre>
<script class="code" type="text/javascript">
$(document).ready(function() {
$.jqplot.config.enablePlugins = false;
var l1 = [18, 36, 14, 11];
var l2 = [[2, 14], [7, 2], [8,5]];
var l3 = [4, 7, 9, 2, 11, 5, 9, 13, 8, 7];
var l4 = [['peech',3], ['cabbage', 2], ['bean', 4], ['orange', 5]];
$("#tabs").tabs();
$("#accordion").accordion();
var plot1 = $.jqplot('chart1', [l1, l2, l3], {
title: "I was hidden",
lengend:{show:true},
series:[{},{yaxis:'y2axis'}, {yaxis:'y3axis'}],
cursor:{show:true, zoom:true},
axesDefaults:{useSeriesColor:true, rendererOptions: { alignTicks: true}}
});
var plot2 = $.jqplot('chart2', [l4], {
height: 200,
width: 300,
series:[{renderer:$.jqplot.PieRenderer}],
legend:{show:true}
});
var catOHLC = [[1, 138.7, 139.68, 135.18, 135.4],
[2, 143.46, 144.66, 139.79, 140.02],
[3, 140.67, 143.56, 132.88, 142.44],
[4, 136.01, 139.5, 134.53, 139.48],
[5, 143.82, 144.56, 136.04, 136.97],
[6, 136.47, 146.4, 136, 144.67],
[7, 124.76, 135.9, 124.55, 135.81],
[8, 123.73, 129.31, 121.57, 122.5]];
var ticks = ['Tue', 'Wed', 'Thu', 'Fri', 'Mon', 'Tue', 'Wed', 'Thr'];
var plot3 = $.jqplot('chart3',[catOHLC],{
grid:{ drawGridlines:true},
title: 'A CandleStick Chart',
axes: {
xaxis: {
renderer:$.jqplot.CategoryAxisRenderer,
ticks:ticks
},
yaxis: {
tickOptions:{formatString:'$%.2f'}
}
},
series: [{renderer:$.jqplot.OHLCRenderer, rendererOptions:{candleStick:true}}]
});
$('#tabs').bind('tabsshow', function(event, ui) {
if (ui.index === 1 && plot1._drawCount === 0) {
plot1.replot();
}
else if (ui.index === 2 && plot2._drawCount === 0) {
plot2.replot();
}
});
$('#accordion').bind('accordionchange', function(event, ui) {
var index = $(this).find("h3").index ( ui.newHeader[0] );
if (index === 1) {
plot3.replot();
}
});
});
</script>
<!-- End example scripts -->
<!-- Don't touch this! -->
<script class="include" type="text/javascript" src="../jquery.jqplot.min.js"></script>
<script type="text/javascript" src="syntaxhighlighter/scripts/shCore.min.js"></script>
<script type="text/javascript" src="syntaxhighlighter/scripts/shBrushJScript.min.js"></script>
<script type="text/javascript" src="syntaxhighlighter/scripts/shBrushXml.min.js"></script>
<!-- End Don't touch this! -->
<!-- Additional plugins go here -->
<script class="include" type="text/javascript" src="../plugins/jqplot.cursor.min.js"></script>
<script class="include" type="text/javascript" src="../plugins/jqplot.pieRenderer.min.js"></script>
<script class="include" type="text/javascript" src="../plugins/jqplot.ohlcRenderer.min.js"></script>
<script class="include" type="text/javascript" src="../plugins/jqplot.categoryAxisRenderer.min.js"></script>
<link class="include" type="text/css" href="jquery-ui/css/smoothness/jquery-ui.min.css" rel="Stylesheet" />
<script class="include" type="text/javascript" src="jquery-ui/js/jquery-ui.min.js"></script>
<!-- End additional plugins -->
</div>
<script type="text/javascript" src="example.min.js"></script>
</body>
</html>