javascript 未捕获的类型错误:使用 highcharts 时未定义不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26822941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 06:32:37  来源:igfitidea点击:

Uncaught TypeError: undefined is not a function when using highcharts

javascriptjqueryhtmlhighcharts

提问by jokomo

When i try to use the simple highcharts example, I get the error:

当我尝试使用简单的 highcharts 示例时,出现错误:

Uncaught TypeError: undefined is not a function 

In addition to :

此外 :

TypeError: undefined is not a function
at Object.Ya.init (https://code.highcharts.com/highcharts.js:190:496)
at Object.Ya (https://code.highcharts.com/highcharts.js:15:312)
at HTMLDocument.eval (eval at <anonymous> (https://localhost:3000/bower_components/jquery/dist/jquery.js:330:5), <anonymous>:4:15)
at fire (https://localhost:3000/bower_components/jquery/dist/jquery.js:3073:30)
at Object.self.add [as done] (https://localhost:3000/bower_components/jquery/dist/jquery.js:3119:7)
at jQuery.fn.ready (https://localhost:3000/bower_components/jquery/dist/jquery.js:3352:25)
at jQuery.fn.init (https://localhost:3000/bower_components/jquery/dist/jquery.js:2794:16)
at jQuery (https://localhost:3000/bower_components/jquery/dist/jquery.js:76:10)
at eval (eval at <anonymous> (https://localhost:3000/bower_components/jquery/dist/jquery.js:330:5), <anonymous>:1:1)

My code is the simple example on the highcharts website:

我的代码是 highcharts 网站上的简单示例:

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<script>
$(function () {

  $('#container').highcharts({
    chart: {
      type: 'bar'
    },
    title: {
      text: 'Fruit Consumption'
    },
    xAxis: {
      categories: ['Apples', 'Bananas', 'Oranges']
    },
    yAxis: {
      title: {
        text: 'Fruit eaten'
      }
    },
    series: [{
      name: 'Jane',
      data: [1, 0, 4]
    }, {
      name: 'John',
      data: [5, 7, 3]
    }]
  });
});

</script>

I've also tried the version where the first line inside is

我也试过里面第一行的版本

var chart = new Highcharts.Chart({

When I print out what Highcharts is, it goes give me the right object. jQuery is loaded and working. What else can I try at this point?

当我打印出 Highcharts 是什么时,它会为我提供正确的对象。jQuery 已加载并正常工作。此时我还能尝试什么?

回答by doog abides

You need to load JQuery before highcharts.

您需要在 highcharts 之前加载 JQuery。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>

回答by jokomo

Okay, this issue was actually really straightforward. There was a script tag loading highcharts in earlier code and it was conflicting with the injection in this line.

好吧,这个问题其实很简单。早期代码中有一个加载 highcharts 的脚本标签,它与此行中的注入冲突。

If you see this error, check if highcharts had been injected already.

如果您看到此错误,请检查是否已注入 highcharts。