出现高映射'未捕获的类型错误:undefined不是函数'并且不加载

Highmaps occuring 'Uncaught TypeError: undefined is not a function ' and not loading?

本文关键字:undefined 错误 加载 类型 函数 高映射 映射      更新时间:2023-09-26

我正在尝试将Highmaps与Highchart一起使用。Highchart可以很好地工作,但Highmaps不适用于Highmaps。

高图未加载高图图形。并且在控制台上出现"Uncaught TypeError:undefined不是函数"错误。我认为它的javascript冲突错误。但是我该怎么解决呢?

代码:

<script src="http://code.highcharts.com/maps/highmaps.js"></script>
<script src="http://code.highcharts.com/maps/modules/data.js"></script>
<script src="http://code.highcharts.com/mapdata/custom/world.js"></script>

<div id="container" style="height: 500px; min-width: 310px; max-width: 800px; margin: 0 auto"></div>
<script>
$(function () {
    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=world-population.json&callback=?', function (data) {
        var mapData = Highcharts.geojson(Highcharts.maps['custom/world']);
        // Correct UK to GB in data
        $.each(data, function () {
            if (this.code === 'UK') {
                this.code = 'GB';
            }
        });
        $('#container').highcharts('Map', {
            chart : {
                borderWidth : 1
            },
            title: {
                text: 'World population 2010 by country'
            },
            subtitle : {
                text : 'Demo of Highcharts map with bubbles'
            },
            legend: {
                enabled: false
            },
            mapNavigation: {
                enabled: true,
                buttonOptions: {
                    verticalAlign: 'bottom'
                }
            },
            series : [{
                name: 'Countries',
                mapData: mapData,
                color: '#E0E0E0',
                enableMouseTracking: false
            }, {
                type: 'mapbubble',
                mapData: mapData,
                name: 'Population 2010',
                joinBy: ['iso-a2', 'code'],
                data: data,
                minSize: 4,
                maxSize: '12%',
                tooltip: {
                    pointFormat: '{point.code}: {point.z} thousands'
                }
            }]
        });
    });
});
</script>

谢谢你的帮助。

您需要在其他highmaps插件之前添加jquery.min.js

$(function () {
    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=world-population.json&callback=?', function (data) {
        var mapData = Highcharts.geojson(Highcharts.maps['custom/world']);
        // Correct UK to GB in data
        $.each(data, function () {
            if (this.code === 'UK') {
                this.code = 'GB';
            }
        });
        $('#container').highcharts('Map', {
            chart : {
                borderWidth : 1
            },
            title: {
                text: 'World population 2010 by country'
            },
            subtitle : {
                text : 'Demo of Highcharts map with bubbles'
            },
            legend: {
                enabled: false
            },
            mapNavigation: {
                enabled: true,
                buttonOptions: {
                    verticalAlign: 'bottom'
                }
            },
            series : [{
                name: 'Countries',
                mapData: mapData,
                color: '#E0E0E0',
                enableMouseTracking: false
            }, {
                type: 'mapbubble',
                mapData: mapData,
                name: 'Population 2010',
                joinBy: ['iso-a2', 'code'],
                data: data,
                minSize: 4,
                maxSize: '12%',
                tooltip: {
                    pointFormat: '{point.code}: {point.z} thousands'
                }
            }]
        });
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://code.highcharts.com/maps/highmaps.js"></script>
<script src="http://code.highcharts.com/maps/modules/data.js"></script>
<script src="http://code.highcharts.com/mapdata/custom/world.js"></script>
<div id="container" style="height: 500px; min-width: 310px; max-width: 800px; margin: 0 auto"></div>