|
16 | 16 | <script language="javascript" type="text/javascript">
|
17 | 17 | $(document).ready(function() {
|
18 | 18 | var plot,
|
19 |
| - container = $('#plot'), // plot container |
20 |
| - ui = $('#ui'), // buttons container |
21 |
| - periods = [ 'day' ], // time periods |
22 |
| - period = periods[0]; // in use time period |
| 19 | + container = $('#plot'), // plot container |
| 20 | + ui = $('#ui'), // buttons container |
| 21 | + periods = [ 'hour', 'day', 'week', 'year' ], // time periods |
| 22 | + period = periods[1]; // the default time period unit - day |
23 | 23 |
|
24 | 24 | // create the ui buttons
|
25 |
| - var createUI = function(container, period, periods) { |
| 25 | + var createUI = function(container, period) { |
26 | 26 | createButton('<< prev ' + period)
|
27 | 27 | .appendTo(container)
|
28 | 28 | .click(function() {
|
|
65 | 65 | plot = $.plot(container, [ data ], options);
|
66 | 66 |
|
67 | 67 | // create the ui buttons
|
68 |
| - createUI(ui, period, periods); |
| 68 | + createUI(ui, period); |
| 69 | + |
| 70 | + $('#snapSelect').change(function() { |
| 71 | + var value = this.options[this.selectedIndex].value; |
| 72 | + ui.empty(); |
| 73 | + createUI(ui, periods[periods.indexOf(value)]); |
| 74 | + plot.snapTo(value, 0); |
| 75 | + }); |
| 76 | + |
69 | 77 | };
|
70 | 78 |
|
71 | 79 | init();
|
72 | 80 | });
|
73 | 81 | </script>
|
74 | 82 |
|
75 | 83 | <div id="plot" style="width:600px;height:200px;"></div>
|
76 |
| -<div id="ui" style="width:600px;height:100px;"></div> |
| 84 | + |
| 85 | +Snap Unit: |
| 86 | +<select id="snapSelect"> |
| 87 | + <option value="hour">Hour</option> |
| 88 | + <option value="day" selected="selected">Day</option> |
| 89 | + <option value="week">Week</option> |
| 90 | + <option value="year">Year</option> |
| 91 | +</select> |
| 92 | + |
| 93 | +<div id="ui" style="width:600px;height:100px;"> |
| 94 | +</div> |
| 95 | +</div> |
77 | 96 | </body>
|
78 | 97 | </html>
|
0 commit comments