【问题标题】:Highcharts Library not workingHighcharts 库不工作
【发布时间】:2014-03-07 02:05:42
【问题描述】:

我目前尝试仅实现来自 highcharts 的示例,只是为了感受一下并尝试一下,但它似乎不起作用。我尝试加载他们的独立框架,不同版本的 jQuery,但图表不会呈现。这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <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>
    </head>
<body>
<script type="text/javascript">
var chart = new Highcharts.Chart({
chart: {
    //alignTicks: false,
    type: 'line',
    renderTo: 'container'
},
        $(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>
<div id="container" style="width:100%; height:400px;"></div>
</body>
</html>

提前致谢。

【问题讨论】:

  • 图表不渲染。
  • 它说“SyntaxError: missing : after property id $(function () {” 但我不确定这是什么意思
  • 现在我得到“未捕获的异常:Highcharts 错误 #13:www.highcharts.com/errors/13”
  • 我仍然收到错误 13。这是我的确切代码 d.pr/i/NLeM
  • 还是什么都没有。同样的错误

标签: javascript jquery highcharts graphing


【解决方案1】:

http://jsfiddle.net/rjreddy78/hgCPa/

<!DOCTYPE html>
<html>
<head>
    <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>
    </head>
<body>
<script type="text/javascript">
        $(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>
<div id="container" style="width:100%; height:400px;"></div>
</body>
</html>

【讨论】:

    【解决方案2】:

    你需要添加

     $(function () { 
       //chart code
     });
    

    $(document).ready(function(){
      //chart code
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 2011-09-01
      • 1970-01-01
      相关资源
      最近更新 更多