使用地图时接收“Highcharts未定义”错误(Highmaps/Highcharts)

问题描述:

我已经使用Highcharts相当多,图表工作得很好,但是我一直试图让Highmaps工作很长一段时间。使用地图时接收“Highcharts未定义”错误(Highmaps/Highcharts)

我相信我已经准备好了一切正确的测试图,我试着让它工作,因为它在JSFiddle中正常工作。

我收到我的浏览器控制台的错误是这样的:

"Uncaught ReferenceError: Highcharts is not defined at https://code.highcharts.com/mapdata/custom/world-highres.js:1:1 (anonymous function) @ world-highres.js:1"

world-highres.js第一部分是:Highcharts.maps["custom/world-highres"] = { ...

有谁知道为什么Highcharts此处将回来为未定义?

我使用Meteor 1.3.5.1,并且我通过NPM安装了Highcharts 5.0.4。

以下是我现在有事情设置:

exampleTemplate.js

import Highcharts from 'highcharts'; 
require('highcharts/modules/map')(Highcharts); 

Template.exampleTemplate.onRendered(function() { 

    // Example data 
    var mymapdata = [ 
    { 
    key: "US", 
    value: 198812 
    }, 
    { 
    key: "GB", 
    value: 52894 
    }, 
    { 
    key: "CA", 
    value: 35572 
    } 
    ]; 

    // Initiate 
    Highcharts.mapChart('country-map-container', { 
     title: { 
      text: 'Highmaps Example' 
     }, 
     subtitle: { 
      text: 'Example' 
     }, 
     mapNavigation: { 
      enabled: true, 
      buttonOptions: { 
       verticalAlign: 'bottom' 
      } 
     }, 
     colorAxis: { 
      min: 0 
     }, 

     series: [{ 
      data: mymapdata, 
      mapData: Highcharts.maps['custom/world-highres'], 
      joinBy: ['iso-a2', 'key'], 
      name: 'Random data', 
      states: { 
       hover: { 
        color: '#a4edba' 
       } 
      }, 
      dataLabels: { 
       enabled: true, 
       format: '{point.name}' 
      } 
     }] 
    }); 

}); 

exampleTemplate.html

<template name="exampleTemplate"> 
    <div id="country-map-container" style="width:100%; height:400px;"></div> 
</template> 

head标签:

<head> 
    <script src="https://code.highcharts.com/mapdata/custom/world-highres.js"></script> 
</head> 

下面是它看起来像上面的代码:

screenshot

我已经尝试了很多不同的东西,花了大量的时间在这,但没有我尝试似乎让它工作...任何帮助,这将非常感激。

+0

我认为你需要这在你的''

太:''。将它放在另一个脚本之前。 – Khang
+0

@Khang谢谢你的回复。我已经给出了一个尝试,但不幸的是,它只是给了我[错误#16](http://www.highcharts.com/errors/16) - “页面上已定义的高层建筑” – U54

+0

它是不确定的,因为高层不是在全局名称空间中定义,使用导入和脚本捆绑时在流星束之前进行评估。 – MasterAM

确保您的顺序如下,

<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/maps/modules/exporting.js"></script> 
<script src="http://code.highcharts.com/mapdata/custom/world-highres.js"></script> 

JSFIDDLE