Highcharts Demo
author(s):
Torstein Hønsi
by Alagar Kamuthurai
HTML
<script src="https://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/maps/modules/exporting.js"></script>
<div id="container"></div>
CSS
#container {
height: 500px;
min-width: 310px;
max-width: 600px;
margin: 0 auto;
}
.loading {
margin-top: 10em;
text-align: center;
color: gray;
}
JavaScript
(async () => {
const mapData = await fetch(
'https://code.highcharts.com/mapdata/custom/world.topo.json'
).then(response => response.json());
const data = await fetch(
'https://cdn.jsdelivr.net/gh/highcharts/[email protected]/samples/data/world-population-density.json'
).then(response => response.json());
// Initialize the chart
Highcharts.mapChart('container', {
title: {
text: 'Predefined zoomed area'
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
mapView: {
projection: {
name: 'WebMercator'
},
zoom: 2.8
},
colorAxis: {
min: 1,
max: 1000,
type: 'logarithmic'
},
legend: {
title: {
text: 'Population density per km²'
}
},
series: [{
data,
mapData,
joinBy: ['iso-a2', 'code'],
name: 'Population density',
states: {
hover: {
color: '#a4edba'
}
},
tooltip: {
valueSuffix: '/km²'
}
}]
});
})();