index.htm 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. margin: 0 auto;
  10. max-width: 400px;
  11. min-width: 380px;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <script src="../../code/highcharts.js"></script>
  17. <script src="../../code/highcharts-more.js"></script>
  18. <script src="../../code/modules/solid-gauge.js"></script>
  19. <div id="container"></div>
  20. <script type="text/javascript">
  21. // Uncomment to style it like Apple Watch
  22. /*
  23. if (!Highcharts.theme) {
  24. Highcharts.setOptions({
  25. chart: {
  26. backgroundColor: 'black'
  27. },
  28. colors: ['#F62366', '#9DFF02', '#0CCDD6'],
  29. title: {
  30. style: {
  31. color: 'silver'
  32. }
  33. },
  34. tooltip: {
  35. style: {
  36. color: 'silver'
  37. }
  38. }
  39. });
  40. }
  41. // */
  42. /**
  43. * In the chart render event, add icons on top of the circular shapes
  44. */
  45. function renderIcons() {
  46. // Move icon
  47. if (!this.series[0].icon) {
  48. this.series[0].icon = this.renderer.path(['M', -8, 0, 'L', 8, 0, 'M', 0, -8, 'L', 8, 0, 0, 8])
  49. .attr({
  50. 'stroke': '#303030',
  51. 'stroke-linecap': 'round',
  52. 'stroke-linejoin': 'round',
  53. 'stroke-width': 2,
  54. 'zIndex': 10
  55. })
  56. .add(this.series[2].group);
  57. }
  58. this.series[0].icon.translate(
  59. this.chartWidth / 2 - 10,
  60. this.plotHeight / 2 - this.series[0].points[0].shapeArgs.innerR -
  61. (this.series[0].points[0].shapeArgs.r - this.series[0].points[0].shapeArgs.innerR) / 2
  62. );
  63. // Exercise icon
  64. if (!this.series[1].icon) {
  65. this.series[1].icon = this.renderer.path(
  66. ['M', -8, 0, 'L', 8, 0, 'M', 0, -8, 'L', 8, 0, 0, 8,
  67. 'M', 8, -8, 'L', 16, 0, 8, 8]
  68. )
  69. .attr({
  70. 'stroke': '#ffffff',
  71. 'stroke-linecap': 'round',
  72. 'stroke-linejoin': 'round',
  73. 'stroke-width': 2,
  74. 'zIndex': 10
  75. })
  76. .add(this.series[2].group);
  77. }
  78. this.series[1].icon.translate(
  79. this.chartWidth / 2 - 10,
  80. this.plotHeight / 2 - this.series[1].points[0].shapeArgs.innerR -
  81. (this.series[1].points[0].shapeArgs.r - this.series[1].points[0].shapeArgs.innerR) / 2
  82. );
  83. // Stand icon
  84. if (!this.series[2].icon) {
  85. this.series[2].icon = this.renderer.path(['M', 0, 8, 'L', 0, -8, 'M', -8, 0, 'L', 0, -8, 8, 0])
  86. .attr({
  87. 'stroke': '#303030',
  88. 'stroke-linecap': 'round',
  89. 'stroke-linejoin': 'round',
  90. 'stroke-width': 2,
  91. 'zIndex': 10
  92. })
  93. .add(this.series[2].group);
  94. }
  95. this.series[2].icon.translate(
  96. this.chartWidth / 2 - 10,
  97. this.plotHeight / 2 - this.series[2].points[0].shapeArgs.innerR -
  98. (this.series[2].points[0].shapeArgs.r - this.series[2].points[0].shapeArgs.innerR) / 2
  99. );
  100. }
  101. Highcharts.chart('container', {
  102. chart: {
  103. type: 'solidgauge',
  104. height: '110%',
  105. events: {
  106. render: renderIcons
  107. }
  108. },
  109. title: {
  110. text: 'Activity',
  111. style: {
  112. fontSize: '24px'
  113. }
  114. },
  115. tooltip: {
  116. borderWidth: 0,
  117. backgroundColor: 'none',
  118. shadow: false,
  119. style: {
  120. fontSize: '16px'
  121. },
  122. pointFormat: '{series.name}<br><span style="font-size:2em; color: {point.color}; font-weight: bold">{point.y}%</span>',
  123. positioner: function (labelWidth) {
  124. return {
  125. x: (this.chart.chartWidth - labelWidth) / 2,
  126. y: (this.chart.plotHeight / 2) + 15
  127. };
  128. }
  129. },
  130. pane: {
  131. startAngle: 0,
  132. endAngle: 360,
  133. background: [{ // Track for Move
  134. outerRadius: '112%',
  135. innerRadius: '88%',
  136. backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[0])
  137. .setOpacity(0.3)
  138. .get(),
  139. borderWidth: 0
  140. }, { // Track for Exercise
  141. outerRadius: '87%',
  142. innerRadius: '63%',
  143. backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[1])
  144. .setOpacity(0.3)
  145. .get(),
  146. borderWidth: 0
  147. }, { // Track for Stand
  148. outerRadius: '62%',
  149. innerRadius: '38%',
  150. backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[2])
  151. .setOpacity(0.3)
  152. .get(),
  153. borderWidth: 0
  154. }]
  155. },
  156. yAxis: {
  157. min: 0,
  158. max: 100,
  159. lineWidth: 0,
  160. tickPositions: []
  161. },
  162. plotOptions: {
  163. solidgauge: {
  164. dataLabels: {
  165. enabled: false
  166. },
  167. linecap: 'round',
  168. stickyTracking: false,
  169. rounded: true
  170. }
  171. },
  172. series: [{
  173. name: 'Move',
  174. data: [{
  175. color: Highcharts.getOptions().colors[0],
  176. radius: '112%',
  177. innerRadius: '88%',
  178. y: 80
  179. }]
  180. }, {
  181. name: 'Exercise',
  182. data: [{
  183. color: Highcharts.getOptions().colors[1],
  184. radius: '87%',
  185. innerRadius: '63%',
  186. y: 65
  187. }]
  188. }, {
  189. name: 'Stand',
  190. data: [{
  191. color: Highcharts.getOptions().colors[2],
  192. radius: '62%',
  193. innerRadius: '38%',
  194. y: 50
  195. }]
  196. }]
  197. });
  198. </script>
  199. </body>
  200. </html>