javascript HighCharts - JQuery - 简单示例不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15889077/
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-27 02:27:55  来源:igfitidea点击:

HighCharts - JQuery - Simple example not working

javascriptjqueryhtmlhighcharts

提问by New_programmer

This simple example from the highcharts website is not working for me (http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/pie-basic/).

highcharts 网站上的这个简单示例对我不起作用(http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/pie -基本/)。

Here is my code:

这是我的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.highcharts.com/js/highcharts.js"></script>

<script type="text/javascript">

    $(function () {
        $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: 'Browser market shares at a specific website, 2010'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage}%</b>',
                percentageDecimals: 1
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        color: '#000000',
                        connectorColor: '#000000',
                        formatter: function() {
                            return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                        }
                    }
                }
            },
            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>
</head>

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

I have just copied it over from the jsfiddle so have no idea why it isn't working!

我刚刚从 jsfiddle 复制了它,所以不知道为什么它不起作用!

Thanks

谢谢

回答by Paul Solans

I couldn't get the HighCharts demos to work locally, but found this answer to another question...

我无法让 HighCharts 演示在本地工作,但找到了另一个问题的答案......

problem is .highchart. Use

问题是.highchart。利用

var chart = new Highcharts.Chart({
chart: {
    //alignTicks: false,
    type: 'line',
    renderTo: 'container'
},
...

}

}

See this page: JSFiddle API examples are broken

请参阅此页面: JSFiddle API 示例已损坏

回答by Ben Felda

The fiddle is actually using the highcharts code from http://code.highcharts.com/highcharts.js.. I tested this link in your code and it seems to be working. I was getting a console error that highcharts method is undefined...with the link you show.

小提琴实际上是使用来自http://code.highcharts.com/highcharts.js..的 highcharts 代码。我在你的代码中测试了这个链接,它似乎工作正常。我收到一个控制台错误,highcharts method is undefined...与您显示的链接有关。