解决创建地图,柱状图和雷达图时的高图与高图冲突

时间:2019-05-26 19:08:40

标签: highcharts

我可以通过在application.js中要求在Ruby on Rails应用程序中创建图表高点图和雷达图:

//= require jquery3
//= require highcharts
//= require highcharts/highcharts-more

然后,我需要添加一个高图地图。但是,调用地图生成函数Highcharts.mapChart('container', {...会引发:

Uncaught TypeError: Highcharts.mapChart is not a function

我似乎可以通过将//= require highcharts替换为//= require highmaps并添加//= require highcharts/modules/map来解决该错误。现在我既有柱形图又有地图。但是删除//= require highcharts会导致在调用雷达图Uncaught ReferenceError: Highcharts is not defined时出错。由于出现冲突,我不能同时要求highcharts和highmaps

Uncaught Error: Highcharts error #16: Highcharts already defined in the page
This error happens if the Highcharts namespace already exists when loading Highcharts or Highstock.

尝试将//= require highmaps放在//= require highcharts/highcharts-more之前可以解决该错误,但会引发两个新错误:Uncaught TypeError: Cannot read property 'prototype' of undefinedUncaught TypeError: Cannot read property 'updateCenter' of undefined。 如何在同一应用程序中同时获取柱,雷达和地图?

1 个答案:

答案 0 :(得分:0)

您不应同时使用Highmapsmap模块。您可以将map插件用作Highcharts的插件:

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/maps/modules/map.js"></script>

实时演示: http://jsfiddle.net/BlackLabel/gbduyLo9/

文档: https://www.highcharts.com/docs/maps/getting-started