042b364b5fd13c1144ba019ebb37dc69db37f604.svn-base 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. .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.highlight(e);
  41. }
  42. }
  43. });
  44. /**
  45. * Override the reset function, we don't need to hide the tooltips and crosshairs.
  46. */
  47. Highcharts.Pointer.prototype.reset = function () {
  48. return undefined;
  49. };
  50. /**
  51. * Highlight a point by showing tooltip, setting hover state and draw crosshair
  52. */
  53. Highcharts.Point.prototype.highlight = function (event) {
  54. this.onMouseOver(); // Show the hover marker
  55. this.series.chart.tooltip.refresh(this); // Show the tooltip
  56. this.series.chart.xAxis[0].drawCrosshair(event, this); // Show the crosshair
  57. };
  58. /**
  59. * Synchronize zooming through the setExtremes event handler.
  60. */
  61. function syncExtremes(e) {
  62. var thisChart = this.chart;
  63. if (e.trigger !== 'syncExtremes') { // Prevent feedback loop
  64. Highcharts.each(Highcharts.charts, function (chart) {
  65. if (chart !== thisChart) {
  66. if (chart.xAxis[0].setExtremes) { // It is null while updating
  67. chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, { trigger: 'syncExtremes' });
  68. }
  69. }
  70. });
  71. }
  72. }
  73. // Get the data. The contents of the data file can be viewed at
  74. // https://github.com/highcharts/highcharts/blob/master/samples/data/activity.json
  75. $.getJSON('http://www.hcharts.cn/datas/jsonp.php?filename=activity.json&callback=?', function (activity) {
  76. $.each(activity.datasets, function (i, dataset) {
  77. // Add X values
  78. dataset.data = Highcharts.map(dataset.data, function (val, j) {
  79. return [activity.xData[j], val];
  80. });
  81. $('<div class="chart">')
  82. .appendTo('#container')
  83. .highcharts({
  84. chart: {
  85. marginLeft: 40, // Keep all charts left aligned
  86. spacingTop: 20,
  87. spacingBottom: 20
  88. },
  89. title: {
  90. text: dataset.name,
  91. align: 'left',
  92. margin: 0,
  93. x: 30
  94. },
  95. credits: {
  96. enabled: false
  97. },
  98. legend: {
  99. enabled: false
  100. },
  101. xAxis: {
  102. crosshair: true,
  103. events: {
  104. setExtremes: syncExtremes
  105. },
  106. labels: {
  107. format: '{value} km'
  108. }
  109. },
  110. yAxis: {
  111. title: {
  112. text: null
  113. }
  114. },
  115. tooltip: {
  116. positioner: function () {
  117. return {
  118. x: this.chart.chartWidth - this.label.width, // right aligned
  119. y: -1 // align to title
  120. };
  121. },
  122. borderWidth: 0,
  123. backgroundColor: 'none',
  124. pointFormat: '{point.y}',
  125. headerFormat: '',
  126. shadow: false,
  127. style: {
  128. fontSize: '18px'
  129. },
  130. valueDecimals: dataset.valueDecimals
  131. },
  132. series: [{
  133. data: dataset.data,
  134. name: dataset.name,
  135. type: dataset.type,
  136. color: Highcharts.getOptions().colors[i],
  137. fillOpacity: 0.3,
  138. tooltip: {
  139. valueSuffix: ' ' + dataset.unit
  140. }
  141. }]
  142. });
  143. });
  144. });
  145. });
  146. </script>
  147. </head>
  148. <body>
  149. <script src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script>
  150. <div id="container"></div>
  151. </body>
  152. </html>