American Map

by Luke Marlow

HTML

<script src="https://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/maps/modules/data.js"></script>
<script src="https://code.highcharts.com/maps/modules/exporting.js"></script>
<script src="https://code.highcharts.com/maps/modules/offline-exporting.js"></script>

<div id="container"></div>

CSS

#container {
  height: 500px;
  min-width: 310px;
  max-width: 800px;
  margin: 0 auto;
}

JavaScript

var data = [
  ['US.CA', Math.floor(Math.random() * 100000)],
  ['US.OR', Math.floor(Math.random() * 100000)],
  ['US.ND', Math.floor(Math.random() * 100000)],
  ['US.NY', Math.floor(Math.random() * 100000)],
  ['US.AL', Math.floor(Math.random() * 100000)],
];

Highcharts.getJSON('https://onelazy.dev/map-us-all.geo.json', function(geojson) {

  // Initiate the chart
  Highcharts.mapChart('container', {
    chart: {
      map: geojson
    },
    title: {
      text: 'American Highmaps Example'
    },
    mapNavigation: {
      enabled: true,
      buttonOptions: {
        verticalAlign: 'bottom'
      }
    },
    colorAxis: {
      tickPixelInterval: 100
    },
    series: [{
      data: data,
      keys: ['hasc', 'value'],
      joinBy: 'hasc',
      name: 'Streams',
      states: {
        hover: {
          color: '#a4edba'
        }
      },
      dataLabels: {
        enabled: true,
        format: '{point.properties.postal}'
      }
    }]
  });
});