2016-11-27 243 views
0

我已經使用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

回答

0

確保您的順序如下,

<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

相關問題