index.htm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Highmaps Example</title>
  6. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  7. <style type="text/css">
  8. ${demo.css}
  9. </style>
  10. <script type="text/javascript">
  11. $(function () {
  12. /*
  13. TODO:
  14. - Check data labels after drilling. Label rank? New positions?
  15. - Not US Mainland text
  16. - Separators
  17. */
  18. var data = Highcharts.geojson(Highcharts.maps['countries/us/us-all']),
  19. // Some responsiveness
  20. small = $('#container').width() < 400;
  21. // Set drilldown pointers
  22. $.each(data, function (i) {
  23. this.drilldown = this.properties['hc-key'];
  24. this.value = i; // Non-random bogus data
  25. });
  26. // Instanciate the map
  27. $('#container').highcharts('Map', {
  28. chart : {
  29. events: {
  30. drilldown: function (e) {
  31. if (!e.seriesOptions) {
  32. var chart = this,
  33. mapKey = 'countries/us/' + e.point.drilldown + '-all',
  34. // Handle error, the timeout is cleared on success
  35. fail = setTimeout(function () {
  36. if (!Highcharts.maps[mapKey]) {
  37. chart.showLoading('<i class="icon-frown"></i> Failed loading ' + e.point.name);
  38. fail = setTimeout(function () {
  39. chart.hideLoading();
  40. }, 1000);
  41. }
  42. }, 3000);
  43. // Show the spinner
  44. chart.showLoading('<i class="icon-spinner icon-spin icon-3x"></i>'); // Font Awesome spinner
  45. // Load the drilldown map
  46. $.getScript('http://code.highcharts.com/mapdata/' + mapKey + '.js', function () {
  47. data = Highcharts.geojson(Highcharts.maps[mapKey]);
  48. // Set a non-random bogus value
  49. $.each(data, function (i) {
  50. this.value = i;
  51. });
  52. // Hide loading and add series
  53. chart.hideLoading();
  54. clearTimeout(fail);
  55. chart.addSeriesAsDrilldown(e.point, {
  56. name: e.point.name,
  57. data: data,
  58. dataLabels: {
  59. enabled: true,
  60. format: '{point.name}'
  61. }
  62. });
  63. });
  64. }
  65. this.setTitle(null, { text: e.point.name });
  66. },
  67. drillup: function () {
  68. this.setTitle(null, { text: 'USA' });
  69. }
  70. }
  71. },
  72. title : {
  73. text : 'Highcharts Map Drilldown'
  74. },
  75. subtitle: {
  76. text: 'USA',
  77. floating: true,
  78. align: 'right',
  79. y: 50,
  80. style: {
  81. fontSize: '16px'
  82. }
  83. },
  84. legend: small ? {} : {
  85. layout: 'vertical',
  86. align: 'right',
  87. verticalAlign: 'middle'
  88. },
  89. colorAxis: {
  90. min: 0,
  91. minColor: '#E6E7E8',
  92. maxColor: '#005645'
  93. },
  94. mapNavigation: {
  95. enabled: true,
  96. buttonOptions: {
  97. verticalAlign: 'bottom'
  98. }
  99. },
  100. plotOptions: {
  101. map: {
  102. states: {
  103. hover: {
  104. color: '#EEDD66'
  105. }
  106. }
  107. }
  108. },
  109. series : [{
  110. data : data,
  111. name: 'USA',
  112. dataLabels: {
  113. enabled: true,
  114. format: '{point.properties.postal-code}'
  115. }
  116. }],
  117. drilldown: {
  118. //series: drilldownSeries,
  119. activeDataLabelStyle: {
  120. color: '#FFFFFF',
  121. textDecoration: 'none',
  122. textShadow: '0 0 3px #000000'
  123. },
  124. drillUpButton: {
  125. relativeTo: 'spacingBox',
  126. position: {
  127. x: 0,
  128. y: 60
  129. }
  130. }
  131. }
  132. });
  133. });
  134. </script>
  135. </head>
  136. <body>
  137. <script src="../../js/highmaps.js"></script>
  138. <script src="../../js/modules/data.js"></script>
  139. <script src="../../js/modules/drilldown.js"></script>
  140. <script src="http://code.highcharts.com/mapdata/countries/us/us-all.js"></script>
  141. <link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
  142. <div id="container" style="height: 500px; min-width: 310px; max-width: 800px; margin: 0 auto"></div>
  143. </body>
  144. </html>