简体   繁体   English

TypeError:$(…)不是函数错误

[英]TypeError: $(…) not a function error

I already checked old threads, but still I could not solve it. 我已经检查了旧线程,但仍然无法解决。

It's regading jquery think but I already put jquery in the file. 这是jquery的想法,但我已经将jquery放在了文件中。

can someone tell me what is the issue here? 有人可以告诉我这里是什么问题吗?

Code is about displaying the graph and on button click of slice display nother graph. 代码是关于显示图形的,并在按钮上单击切片显示其他图形。

Code: 码:

<!DOCTYPE html>
<html lang="en">
    <head>
    <script src="http://code.highcharts.com/highcharts.js"></script>
        <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script src="http://code.highcharts.com/modules/exporting.js"></script>
        <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>

</head>
    <body>

    <div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

    </body>
        <script>
    $(function () {
            $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: 1,//null,
                plotShadow: false
            },
            title: {
                text: 'Browser market shares at a specific website, 2014'
            },
            tooltip: {

                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'

                    }
                }
                }
            },
            series: [{
                type: 'pie',
                name: 'Browser share',

                data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                name: 'Chrome',
                y: 12.8,
                sliced: true,
                    selected: true
            },
        ['Safari',    8.5],
            ['Opera',     6.2],
            ['Others',   0.7]
            ]
            }]
            });
        });       
        </script>
<html>

Highcharts depends on jQuery. Highcharts取决于jQuery。 So you must include 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>

You need to refer to JQuery before refering to highchart scripts. 在引用highchart脚本之前,您需要引用JQuery。

A few changes would be: 一些变化将是:

  1. refer to just one JQuery 只引用一个jQuery

  2. Inclose your script in $(document).ready(function(){}); 将脚本包含在$(document).ready(function(){})中;

Please see the updated code: 请查看更新的代码:

<html lang="en">
    <head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>

</head>
    <body>

    <div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

    </body>
        <script>
$(document).ready(function(){
    $(function () {
            $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: 1,//null,
                plotShadow: false
            },
            title: {
                text: 'Browser market shares at a specific website, 2014'
            },
            tooltip: {

                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'

                    }
                }
                }
            },
            series: [{
                type: 'pie',
                name: 'Browser share',

                data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                name: 'Chrome',
                y: 12.8,
                sliced: true,
                    selected: true
            },
        ['Safari',    8.5],
            ['Opera',     6.2],
            ['Others',   0.7]
            ]
            }]
            });
        });    
 });    
        </script>
<html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM