index.htm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=us-counties-unemployment.json&callback=?', function (data) {
  13. /**
  14. * Data parsed from http://www.bls.gov/lau/#tables
  15. *
  16. * 1. Go to http://www.bls.gov/lau/laucntycur14.txt (or similar, updated datasets)
  17. * 2. In the Chrome Developer tools console, run this code:
  18. * copy(JSON.stringify(document.body.innerHTML.split('\n').filter(function (s) { return s.indexOf('<PUT DATE HERE IN FORMAT e.g. Feb-14>') !== -1; }).map(function (row) { row = row.split('|'); return { code: 'us-' + row[3].trim().slice(-2).toLowerCase() + '-' + row[2].trim(), name: row[3].trim(), value: parseFloat(row[8]) }; })))
  19. * 3. The data is now on your clipboard, paste it below
  20. */
  21. var countiesMap = Highcharts.geojson(Highcharts.maps['countries/us/us-all-all']),
  22. lines = Highcharts.geojson(Highcharts.maps['countries/us/us-all-all'], 'mapline'),
  23. options;
  24. // Add state acronym for tooltip
  25. Highcharts.each(countiesMap, function (mapPoint) {
  26. mapPoint.name = mapPoint.name + ', ' + mapPoint.properties['hc-key'].substr(3, 2);
  27. });
  28. options = {
  29. chart: {
  30. borderWidth: 1,
  31. marginRight: 50 // for the legend
  32. },
  33. title: {
  34. text: 'US Counties unemployment rates, April 2015'
  35. },
  36. legend: {
  37. title: {
  38. text: 'Unemployment<br>rate',
  39. style: {
  40. color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
  41. }
  42. },
  43. layout: 'vertical',
  44. align: 'right',
  45. floating: true,
  46. valueDecimals: 0,
  47. valueSuffix: '%',
  48. backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'rgba(255, 255, 255, 0.85)',
  49. symbolRadius: 0,
  50. symbolHeight: 14
  51. },
  52. mapNavigation: {
  53. enabled: true
  54. },
  55. colorAxis: {
  56. dataClasses: [{
  57. from: 0,
  58. to: 2,
  59. color: "#F1EEF6"
  60. }, {
  61. from: 2,
  62. to: 4,
  63. color: "#D4B9DA"
  64. }, {
  65. from: 4,
  66. to: 6,
  67. color: "#C994C7"
  68. }, {
  69. from: 6,
  70. to: 8,
  71. color: "#DF65B0"
  72. }, {
  73. from: 8,
  74. to: 10,
  75. color: "#DD1C77"
  76. }, {
  77. from: 10,
  78. color: "#980043"
  79. }]
  80. },
  81. plotOptions: {
  82. mapline: {
  83. showInLegend: false,
  84. enableMouseTracking: false
  85. }
  86. },
  87. series: [{
  88. mapData: countiesMap,
  89. data: data,
  90. joinBy: ['hc-key', 'code'],
  91. name: 'Unemployment rate',
  92. tooltip: {
  93. valueSuffix: '%'
  94. },
  95. borderWidth: 0.5,
  96. states: {
  97. hover: {
  98. color: '#bada55'
  99. }
  100. }
  101. }, {
  102. type: 'mapline',
  103. name: 'State borders',
  104. data: [lines[0]],
  105. color: 'white'
  106. }, {
  107. type: 'mapline',
  108. name: 'Separator',
  109. data: [lines[1]],
  110. color: 'gray'
  111. }]
  112. };
  113. // Instanciate the map
  114. $('#container').highcharts('Map', options);
  115. });
  116. });
  117. </script>
  118. </head>
  119. <body>
  120. <div id="container" style="height: 520px; min-width: 310px; width: 800px; margin: 0 auto; text-align:center; line-height: 520px">
  121. Downloading map...
  122. </div>
  123. <script src="../../js/highmaps.js"></script>
  124. <script src="../../js/modules/data.js"></script>
  125. <script src="../../js/modules/exporting.js"></script>
  126. <script src="http://code.highcharts.com/mapdata/countries/us/us-all-all.js"></script>
  127. </body>
  128. </html>