index.htm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. .outer {
  9. width: 600px;
  10. height: 200px;
  11. margin: 0 auto;
  12. }
  13. .outer .chart-container {
  14. width: 300px;
  15. float: left;
  16. height: 200px;
  17. }
  18. .highcharts-yaxis-grid .highcharts-grid-line {
  19. display: none;
  20. }
  21. @media (max-width: 600px) {
  22. .outer {
  23. width: 100%;
  24. height: 400px;
  25. }
  26. .outer .chart-container {
  27. width: 300px;
  28. float: none;
  29. margin: 0 auto;
  30. }
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <script src="../../code/highcharts.js"></script>
  36. <script src="../../code/highcharts-more.js"></script>
  37. <script src="../../code/modules/solid-gauge.js"></script>
  38. <div class="outer">
  39. <div id="container-speed" class="chart-container"></div>
  40. <div id="container-rpm" class="chart-container"></div>
  41. </div>
  42. <script type="text/javascript">
  43. var gaugeOptions = {
  44. chart: {
  45. type: 'solidgauge'
  46. },
  47. title: null,
  48. pane: {
  49. center: ['50%', '85%'],
  50. size: '140%',
  51. startAngle: -90,
  52. endAngle: 90,
  53. background: {
  54. backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#EEE',
  55. innerRadius: '60%',
  56. outerRadius: '100%',
  57. shape: 'arc'
  58. }
  59. },
  60. tooltip: {
  61. enabled: false
  62. },
  63. // the value axis
  64. yAxis: {
  65. stops: [
  66. [0.1, '#55BF3B'], // green
  67. [0.5, '#DDDF0D'], // yellow
  68. [0.9, '#DF5353'] // red
  69. ],
  70. lineWidth: 0,
  71. minorTickInterval: null,
  72. tickAmount: 2,
  73. title: {
  74. y: -70
  75. },
  76. labels: {
  77. y: 16
  78. }
  79. },
  80. plotOptions: {
  81. solidgauge: {
  82. dataLabels: {
  83. y: 5,
  84. borderWidth: 0,
  85. useHTML: true
  86. }
  87. }
  88. }
  89. };
  90. // The speed gauge
  91. var chartSpeed = Highcharts.chart('container-speed', Highcharts.merge(gaugeOptions, {
  92. yAxis: {
  93. min: 0,
  94. max: 200,
  95. title: {
  96. text: 'Speed'
  97. }
  98. },
  99. credits: {
  100. enabled: false
  101. },
  102. series: [{
  103. name: 'Speed',
  104. data: [80],
  105. dataLabels: {
  106. format: '<div style="text-align:center"><span style="font-size:25px;color:' +
  107. ((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y}</span><br/>' +
  108. '<span style="font-size:12px;color:silver">km/h</span></div>'
  109. },
  110. tooltip: {
  111. valueSuffix: ' km/h'
  112. }
  113. }]
  114. }));
  115. // The RPM gauge
  116. var chartRpm = Highcharts.chart('container-rpm', Highcharts.merge(gaugeOptions, {
  117. yAxis: {
  118. min: 0,
  119. max: 5,
  120. title: {
  121. text: 'RPM'
  122. }
  123. },
  124. series: [{
  125. name: 'RPM',
  126. data: [1],
  127. dataLabels: {
  128. format: '<div style="text-align:center"><span style="font-size:25px;color:' +
  129. ((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y:.1f}</span><br/>' +
  130. '<span style="font-size:12px;color:silver">* 1000 / min</span></div>'
  131. },
  132. tooltip: {
  133. valueSuffix: ' revolutions/min'
  134. }
  135. }]
  136. }));
  137. // Bring life to the dials
  138. setInterval(function () {
  139. // Speed
  140. var point,
  141. newVal,
  142. inc;
  143. if (chartSpeed) {
  144. point = chartSpeed.series[0].points[0];
  145. inc = Math.round((Math.random() - 0.5) * 100);
  146. newVal = point.y + inc;
  147. if (newVal < 0 || newVal > 200) {
  148. newVal = point.y - inc;
  149. }
  150. point.update(newVal);
  151. }
  152. // RPM
  153. if (chartRpm) {
  154. point = chartRpm.series[0].points[0];
  155. inc = Math.random() - 0.5;
  156. newVal = point.y + inc;
  157. if (newVal < 0 || newVal > 5) {
  158. newVal = point.y - inc;
  159. }
  160. point.update(newVal);
  161. }
  162. }, 2000);
  163. </script>
  164. </body>
  165. </html>