index.htm 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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://cdn.hcharts.cn/jquery/jquery-1.8.3.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: 'easeOutBounce'
  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. /**
  157. * Easing function from https://github.com/danro/easing-js/blob/master/easing.js
  158. */
  159. Math.easeOutBounce = function (pos) {
  160. if ((pos) < (1 / 2.75)) {
  161. return (7.5625 * pos * pos);
  162. }
  163. if (pos < (2 / 2.75)) {
  164. return (7.5625 * (pos -= (1.5 / 2.75)) * pos + 0.75);
  165. }
  166. if (pos < (2.5 / 2.75)) {
  167. return (7.5625 * (pos -= (2.25 / 2.75)) * pos + 0.9375);
  168. }
  169. return (7.5625 * (pos -= (2.625 / 2.75)) * pos + 0.984375);
  170. };
  171. </script>
  172. </head>
  173. <body>
  174. <script src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script>
  175. <script src="http://cdn.hcharts.cn/highcharts/highcharts-more.js"></script>
  176. <div id="container" style="width: 300px; height: 300px; margin: 0 auto"></div>
  177. </body>
  178. </html>