index.htm 4.9 KB

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