PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/js/highcharts/examples/synchronized-charts/index.htm

https://gitlab.com/shides-ac/HitOrMiss
HTML | 157 lines | 145 code | 11 blank | 1 comment | 0 complexity | ace6ed4bc8c902744d79df9c104006b5 MD5 | raw file
  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="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  7. <style type="text/css">
  8. .chart {
  9. min-width: 320px;
  10. max-width: 800px;
  11. height: 220px;
  12. margin: 0 auto;
  13. }
  14. </style>
  15. <!-- http://doc.jsfiddle.net/use/hacks.html#css-panel-hack -->
  16. <meta name="viewport" content="width=device-width, initial-scale=1" />
  17. <style>
  18. </style>
  19. <script type="text/javascript">
  20. /*
  21. The purpose of this demo is to demonstrate how multiple charts on the same page can be linked
  22. through DOM and Highcharts events and API methods. It takes a standard Highcharts config with a
  23. small variation for each data set, and a mouse/touch event handler to bind the charts together.
  24. */
  25. $(function () {
  26. /**
  27. * In order to synchronize tooltips and crosshairs, override the
  28. * built-in events with handlers defined on the parent element.
  29. */
  30. $('#container').bind('mousemove touchmove touchstart', function (e) {
  31. var chart,
  32. point,
  33. i,
  34. event;
  35. for (i = 0; i < Highcharts.charts.length; i = i + 1) {
  36. chart = Highcharts.charts[i];
  37. event = chart.pointer.normalize(e.originalEvent); // Find coordinates within the chart
  38. point = chart.series[0].searchPoint(event, true); // Get the hovered point
  39. if (point) {
  40. point.onMouseOver(); // Show the hover marker
  41. chart.tooltip.refresh(point); // Show the tooltip
  42. chart.xAxis[0].drawCrosshair(event, point); // Show the crosshair
  43. }
  44. }
  45. });
  46. /**
  47. * Override the reset function, we don't need to hide the tooltips and crosshairs.
  48. */
  49. Highcharts.Pointer.prototype.reset = function () {
  50. return undefined;
  51. };
  52. /**
  53. * Synchronize zooming through the setExtremes event handler.
  54. */
  55. function syncExtremes(e) {
  56. var thisChart = this.chart;
  57. if (e.trigger !== 'syncExtremes') { // Prevent feedback loop
  58. Highcharts.each(Highcharts.charts, function (chart) {
  59. if (chart !== thisChart) {
  60. if (chart.xAxis[0].setExtremes) { // It is null while updating
  61. chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, { trigger: 'syncExtremes' });
  62. }
  63. }
  64. });
  65. }
  66. }
  67. // Get the data. The contents of the data file can be viewed at
  68. // https://github.com/highcharts/highcharts/blob/master/samples/data/activity.json
  69. $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=activity.json&callback=?', function (activity) {
  70. $.each(activity.datasets, function (i, dataset) {
  71. // Add X values
  72. dataset.data = Highcharts.map(dataset.data, function (val, j) {
  73. return [activity.xData[j], val];
  74. });
  75. $('<div class="chart">')
  76. .appendTo('#container')
  77. .highcharts({
  78. chart: {
  79. marginLeft: 40, // Keep all charts left aligned
  80. spacingTop: 20,
  81. spacingBottom: 20
  82. },
  83. title: {
  84. text: dataset.name,
  85. align: 'left',
  86. margin: 0,
  87. x: 30
  88. },
  89. credits: {
  90. enabled: false
  91. },
  92. legend: {
  93. enabled: false
  94. },
  95. xAxis: {
  96. crosshair: true,
  97. events: {
  98. setExtremes: syncExtremes
  99. },
  100. labels: {
  101. format: '{value} km'
  102. }
  103. },
  104. yAxis: {
  105. title: {
  106. text: null
  107. }
  108. },
  109. tooltip: {
  110. positioner: function () {
  111. return {
  112. x: this.chart.chartWidth - this.label.width, // right aligned
  113. y: -1 // align to title
  114. };
  115. },
  116. borderWidth: 0,
  117. backgroundColor: 'none',
  118. pointFormat: '{point.y}',
  119. headerFormat: '',
  120. shadow: false,
  121. style: {
  122. fontSize: '18px'
  123. },
  124. valueDecimals: dataset.valueDecimals
  125. },
  126. series: [{
  127. data: dataset.data,
  128. name: dataset.name,
  129. type: dataset.type,
  130. color: Highcharts.getOptions().colors[i],
  131. fillOpacity: 0.3,
  132. tooltip: {
  133. valueSuffix: ' ' + dataset.unit
  134. }
  135. }]
  136. });
  137. });
  138. });
  139. });
  140. </script>
  141. </head>
  142. <body>
  143. <script src="https://code.highcharts.com/highcharts.js"></script>
  144. <div id="container"></div>
  145. </body>
  146. </html>