Highcharts Demo
author(s): Torstein Hønsi
by sgearhart2
HTML
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<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>
<script src="https://code.highcharts.com/mapdata/countries/us/custom/us-small.js"></script>
<script>
let pacFeature = {
"type" : "Feature",
"id" : 1,
"geometry" : {
"type" : "Polygon",
"coordinates" : [
[
[
-2119612.0887759626,
1291191.5078662261
],
[
-2123539.3159624934,
1295494.967470631
],
[
-2119940.5065915659,
1302505.1757035963
],
[
-2129531.2618471012,
1336716.128928531
],
[
-2125039.1416337341,
1344603.1442031451
],
[
-2126443.0047004148,
1360194.7197437026
],
[
-2116087.6780085638,
1369190.9110709988
],
[
-2116471.0117267668,
1381176.18884027
],
[
-2109377.2660898343,
1386377.2887873091
],
[
-2108074.1708279401,
1390689.014392104
],
[
-2124616.6195136681,
1396286.2259579599
],
[
-2158151.5618064925,
1388368.5138818882
],
[
-2200279.3322074488,
1384507.6378985047
],
[
-2313989.1176083758,
1356444.874365598
],
[
...
CSS
#container {
height: 500px;
min-width: 310px;
max-width: 600px;
margin: 0 auto;
}
.loading {
margin-top: 10em;
text-align: center;
color: gray;
}
JavaScript
$.getJSON('https://cdn.jsdelivr.net/gh/highcharts/[email protected]/samples/data/us-population-density.json', function (data) {
// Make codes uppercase to match the map data
$.each(data, function () {
this.code = this.code.toUpperCase();
});
// Instantiate the map
Highcharts.mapChart('container', {
chart: {
map: 'countries/us/custom/us-small',
borderWidth: 1
},
title: {
text: 'US population density (/km²)'
},
exporting: {
sourceWidth: 600,
sourceHeight: 500
},
legend: {
layout: 'horizontal',
borderWidth: 0,
backgroundColor: 'rgba(255,255,255,0.85)',
floating: true,
verticalAlign: 'top',
y: 25
},
mapNavigation: {
enabled: true
},
colorAxis: {
min: 1,
type: 'logarithmic',
minColor: '#EEEEFF',
maxColor: '#000022',
stops: [
[0, '#EFEFFF'],
[0.67, '#4444FF'],
[1, '#000022']
]
},
series: [{
animation: {
duration: 1000
},
data: data,
joinBy: ['postal-code', 'code'],
dataLabels: {
enabled: true,
color: '#FFFFFF',
format: '{point.code}'
},
name: 'Population density',
tooltip: {
pointFormat: '{point.code}: {point.value}/km²'
}
}]
});
});