index.htm 4.8 KB

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