Categorized areas
author(s): Torstein Hønsi
by koh_edwin
HTML
<script src="https://code.highcharts.com/maps/highmaps.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/maps/modules/data.js"></script>
<script src="https://code.highcharts.com/maps/modules/accessibility.js"></script>
<div id="container"></div>
CSS
#container {
height: 500px;
min-width: 310px;
max-width: 480px;
margin: 0 auto;
}
JavaScript
(async () => {
const topology = await fetch(
'https://code.highcharts.com/mapdata/custom/europe.topo.json'
).then(response => response.json());
console.log(topology)
// Instantiate the map
Highcharts.mapChart('container', {
chart: {
map: topology,
spacingBottom: 20
},
title: {
text: 'Europe time zones'
},
accessibility: {
series: {
descriptionFormat: 'Timezone {series.name} with {series.points.length} countries.'
},
point: {
valueDescriptionFormat: '{point.name}.'
}
},
legend: {
enabled: true
},
plotOptions: {
map: {
allAreas: false,
joinBy: ['iso-a2', 'code'],
dataLabels: {
enabled: true,
color: '#FFFFFF',
style: {
fontWeight: 'bold'
},
// Only show dataLabels for areas with high label rank
format: null,
formatter: function () {
if (
this.point.properties &&
this.point.properties.labelrank.toString() < 5
) {
return this.point.properties['iso-a2'];
}
}
},
tooltip: {
headerFormat: '',
pointFormat: '{point.name}: <b>{series.name}</b>'
}
}
},
series: [{
name: 'UTC',
data: ['IE', 'IS', 'GB', 'PT'].map(code => ({ code }))
}, {
name: 'UTC + 1',
data: [
'NO', 'SE', 'DK', 'DE', 'NL', 'BE', 'LU', 'ES', 'FR', 'PL',
'CZ', 'AT', 'CH', 'LI', 'SK', 'HU',...