You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
5.3 KiB

9 years ago
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Highcharts Example</title>
  6. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  7. <style type="text/css">
  8. ${demo.css}
  9. </style>
  10. <script type="text/javascript">
  11. $(function () {
  12. /**
  13. * Get the current time
  14. */
  15. function getNow() {
  16. var now = new Date();
  17. return {
  18. hours: now.getHours() + now.getMinutes() / 60,
  19. minutes: now.getMinutes() * 12 / 60 + now.getSeconds() * 12 / 3600,
  20. seconds: now.getSeconds() * 12 / 60
  21. };
  22. }
  23. /**
  24. * Pad numbers
  25. */
  26. function pad(number, length) {
  27. // Create an array of the remaining length + 1 and join it with 0's
  28. return new Array((length || 2) + 1 - String(number).length).join(0) + number;
  29. }
  30. var now = getNow();
  31. // Create the chart
  32. $('#container').highcharts({
  33. chart: {
  34. type: 'gauge',
  35. plotBackgroundColor: null,
  36. plotBackgroundImage: null,
  37. plotBorderWidth: 0,
  38. plotShadow: false,
  39. height: 200
  40. },
  41. credits: {
  42. enabled: false
  43. },
  44. title: {
  45. text: 'The Highcharts clock'
  46. },
  47. pane: {
  48. background: [{
  49. // default background
  50. }, {
  51. // reflex for supported browsers
  52. backgroundColor: Highcharts.svg ? {
  53. radialGradient: {
  54. cx: 0.5,
  55. cy: -0.4,
  56. r: 1.9
  57. },
  58. stops: [
  59. [0.5, 'rgba(255, 255, 255, 0.2)'],
  60. [0.5, 'rgba(200, 200, 200, 0.2)']
  61. ]
  62. } : null
  63. }]
  64. },
  65. yAxis: {
  66. labels: {
  67. distance: -20
  68. },
  69. min: 0,
  70. max: 12,
  71. lineWidth: 0,
  72. showFirstLabel: false,
  73. minorTickInterval: 'auto',
  74. minorTickWidth: 1,
  75. minorTickLength: 5,
  76. minorTickPosition: 'inside',
  77. minorGridLineWidth: 0,
  78. minorTickColor: '#666',
  79. tickInterval: 1,
  80. tickWidth: 2,
  81. tickPosition: 'inside',
  82. tickLength: 10,
  83. tickColor: '#666',
  84. title: {
  85. text: 'Powered by<br/>Highcharts',
  86. style: {
  87. color: '#BBB',
  88. fontWeight: 'normal',
  89. fontSize: '8px',
  90. lineHeight: '10px'
  91. },
  92. y: 10
  93. }
  94. },
  95. tooltip: {
  96. formatter: function () {
  97. return this.series.chart.tooltipText;
  98. }
  99. },
  100. series: [{
  101. data: [{
  102. id: 'hour',
  103. y: now.hours,
  104. dial: {
  105. radius: '60%',
  106. baseWidth: 4,
  107. baseLength: '95%',
  108. rearLength: 0
  109. }
  110. }, {
  111. id: 'minute',
  112. y: now.minutes,
  113. dial: {
  114. baseLength: '95%',
  115. rearLength: 0
  116. }
  117. }, {
  118. id: 'second',
  119. y: now.seconds,
  120. dial: {
  121. radius: '100%',
  122. baseWidth: 1,
  123. rearLength: '20%'
  124. }
  125. }],
  126. animation: false,
  127. dataLabels: {
  128. enabled: false
  129. }
  130. }]
  131. },
  132. // Move
  133. function (chart) {
  134. setInterval(function () {
  135. now = getNow();
  136. var hour = chart.get('hour'),
  137. minute = chart.get('minute'),
  138. second = chart.get('second'),
  139. // run animation unless we're wrapping around from 59 to 0
  140. animation = now.seconds === 0 ?
  141. false :
  142. {
  143. easing: 'easeOutElastic'
  144. };
  145. // Cache the tooltip text
  146. chart.tooltipText =
  147. pad(Math.floor(now.hours), 2) + ':' +
  148. pad(Math.floor(now.minutes * 5), 2) + ':' +
  149. pad(now.seconds * 5, 2);
  150. hour.update(now.hours, true, animation);
  151. minute.update(now.minutes, true, animation);
  152. second.update(now.seconds, true, animation);
  153. }, 1000);
  154. });
  155. });
  156. // Extend jQuery with some easing (copied from jQuery UI)
  157. $.extend($.easing, {
  158. easeOutElastic: function (x, t, b, c, d) {
  159. var s=1.70158;var p=0;var a=c;
  160. if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
  161. if (a < Math.abs(c)) { a=c; var s=p/4; }
  162. else var s = p/(2*Math.PI) * Math.asin (c/a);
  163. return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
  164. }
  165. });
  166. </script>
  167. </head>
  168. <body>
  169. <script src="../../js/highcharts.js"></script>
  170. <script src="../../js/highcharts-more.js"></script>
  171. <div id="container" style="width: 300px; height: 300px; margin: 0 auto"></div>
  172. </body>
  173. </html>