Highcharts Demo

author(s): Torstein Hønsi

by Geo George

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>


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

CSS

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

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

JavaScript

(async () => {

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

    Highcharts.getJSON('https://cdn.jsdelivr.net/gh/highcharts/[email protected]/samples/data/world-population-density.json', function (data) {

data = [
{
"code": "ZW",
"code3": "ZWE",
"name": "Zimbabwe",
"value": 41.75,
color: 'red',
states:{
  hover:{
  	color: "green"
  }
}
},
{
code: "ZA",
code3: "ZAF",
name: "South Africa",
value: 46.18,
states:{
  hover:{
  	color: "orange"
  }
}
}
]
        // Initialize the chart
        Highcharts.mapChart('container', {

            chart: {
                borderWidth: 1,
                reflow: false
            },

            title: {
                text: 'Chart with reflow disabled'
            },

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

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

            legend: {
                title: {
                    text: 'Population per km²'
                },
                backgroundColor: 'rgba(255,255,255,0.85)'
            },

            // The map series
            series: [{
                data: data,
                mapData: topology,
                joinBy: ['iso-a2', 'code'],
                name: 'Population density',
                states: {
                    hover: {
                        color: '#a4edba'
                    }
                },
                tooltip: {
                    valueSuffix: '/km²'
                }
            }]
        });
    });
})();