Highcharts Demo

author(s): Torstein Hønsi

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>

<button id="ecuador" class="highcharts-demo-button">Zoom to Ecuador</button>
<button id="south-korea" class="highcharts-demo-button">Zoom to South Korea</button>
<button id="zoom-out" class="highcharts-demo-button">Zoom out</button>

CSS

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

.loading {
    margin-top: 10em;
    text-align: center;
    color: gray;
}

.highcharts-demo-button {
    background: var(--highcharts-neutral-color-5, #f2f2f2);
    border: none;
    border-radius: 4px;
    color: var(--highcharts-neutral-color-100, #000);
    cursor: pointer;
    display: inline-block;
    font-size: 0.8rem;
    padding: 0.5rem 1.5rem;
    margin: 0.5rem -5px 0.5rem 10px;
    transition: background 250ms;
}

.highcharts-demo-button:hover {
    background: var(--highcharts-neutral-color-10, #e6e6e6);
}

JavaScript

(async () => {

    const topology = await fetch(
        'https://code.highcharts.com/mapdata/custom/world-highres.topo.json'
    ).then(response => response.json());

    const data = await fetch(
        'https://cdn.jsdelivr.net/gh/highcharts/highcharts@v7.0.0/samples/data/world-population-density.json'
    ).then(response => response.json());

    // Assign id's
    data.forEach(function (p) {
        p.id = p.code;
    });

    // Initialize the chart
    const chart = Highcharts.mapChart('container', {

        title: {
            text: 'Zoom to point'
        },

        subtitle: {
            text: 'Click a country to zoom to it. Use buttons below map for ' +
                'selected tests.'
        },

        legend: {
            title: {
                text: 'Population density per km²'
            }
        },

        colorAxis: {
            min: 1,
            max: 1000,
            type: 'logarithmic'
        },

        mapNavigation: {
            enabled: true,
            buttonOptions: {
                verticalAlign: 'bottom'
            }
        },

        series: [{
            data: data,
            mapData: topology,
            joinBy: ['iso-a2', 'code'],
            name: 'Population density',
            allowPointSelect: true,
            cursor: 'pointer',
            events: {
                click: function (e) {
                    e.point.zoomTo();
                }
            },
            tooltip: {
                pointFormat: '{point.id} {point.name}',
                valueSuffix: '/km²'
            }
        }]
    });

    // Activate the buttons
    document.getElementById('ecuador').addEventListener('click', function () {
        chart.get('EC').zoomTo();
    });
    document.getElementById(
        'south-korea'
    ).addEventListener('click', function () {
        chart.get('KR').zoomTo();
    });
    document.getElementById('zoom-out').addEventListener('click', function () {
        chart.mapZoom();
   ...